Linux Web server Nginx

1, What is web service?

  Web service is a service-oriented architecture technology, which provides services through standard Web protocols to ensure that application services of different platforms can interoperate. According to the definition of W3C, Web service should be a software system to support the interactive operation of different machines in the network. Network services are usually composed of many application program interfaces. They execute the service requests submitted by customers through the network, such as the remote server of the Internet.

2, Common web server software


Official website:

  Apache is the world's No. 1 Web server software. It can run on almost all widely used computer platforms. It is one of the most popular Web server-side software because of its cross platform and security. It is fast and reliable, and can compile interpreters such as Perl/Python into the server through simple API expansion.


Official website:

Nginx is a lightweight Web server / reverse proxy server and e-mail (IMAP/POP3) proxy server, which is distributed under BSD like protocol. Its characteristics are less memory and concurrent capability. In fact, nginx's concurrent capability is better in the same type of Web server. Chinese mainland users use Baidu website: Baidu, Jingdong, Sina, NetEase, Tencent, Taobao, etc.

Comparison of network models

apache uses the select model
nginx uses the epoll model

3, Nginx command

  • -v: Print version number

  • -5: Print version number and configuration items

  • -t: Check configuration file

  • -T: Test the configuration file and start

  • -q: Print error log

  • -s [option]: operation process
    Stop   stop
    quit   exit
    reopen   restart
    Reload   reload

  • -p: Specify the working directory of nginx

  • -e: Specify the error log path

  • -c: Specifies the path to the configuration file

  • -g: Set a global Nginx configuration item

    [root@web01 ~]# nginx -g 'daemon off;'

4, Nginx profile

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/;

events {
    worker_connections  1024;

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
  1. User: Specifies the nginx startup user
  2. worker_processes: defines the number of nginx worker processes
  3. error_log: error log path
  4. pid: the file path where pid is stored
  5. events: module configuration
    • worker_connections: how many requests can each worker process access simultaneously
    • use: specify the network model of Nginx (this item does not need to be configured by default)
  6. http: module of web Service
    • include: loads external configuration items
    • default_type: if the file type cannot be found, it will be processed according to the specified default type
    • log_format: defines the log format
      log_format json '{"@timestamp":"$time_iso8601",'
      access_log /var/log/nginx/access.log json ;
    • sendfile: efficient reading of files
    • keepalive_timeout: the maximum time for a long connection to remain connected
    • server: website module
      • listen: listening port
      • server_name: define domain name
      • location: access path
        • root: Specifies the URL path
        • Index: Specifies the index file of the web address

Added by IwnfuM on Mon, 03 Jan 2022 17:14:10 +0200