Nginx Advanced (a)

1. The main scenario

  • Static resource services provided by the local file system, it is often said static resources isolated
  • Using its powerful performance, caching, load balancing, reverse proxy to provide services for the server
  • Providing an API service

2. advantage

  • High concurrency, high performance
  • Good scalability
  • High reliability
  • Hot deployment
  • BSD license

3.Nginx composition

  • Nginx binary executable (compiled by the original code module of a file)
  • Nginx.conf configuration file (Nginx control behavior)
  • the access.log (http request information recording each)
  • error.log (log errors, locate the problem)

4.Nginx grammar Introduction

  • Configuration file consists of command and instruction block
  • {} Block of instructions to the plurality of instructions braces are organized
  • Add comments using the # symbol to improve readability
  • compositions include statement allows multiple profiles to enhance maintainability
  • Use $ notation using variables
  • Parameter support for regular expressions portion of the instruction

5. Introduction to the command line

  • nginx -s reload to reload the configuration file
  • nginx -s stop immediately stop service
  • nginx -s quit friendly stop service, which is nginx Once processed the request to stop
  • nignx -s reopen resume logging
  • nginx -t configuration file syntax to detect if there are problems
  • nginx nginx -v print version, compile information

6. Profile structure nginx.conf

Building blocks Explanation
main The main control users and groups Nginx subprocess belongs, the number of sub-process is derived, and the position error log level, pid location, priority sub-process, the process of the CPU corresponds to the number of file descriptors, a process can be opened like
events Connection control process Nginx
http The main configuration block Nginx http request process, most are arranged in the inside be
server Nginx host configuration block, can be used to configure multiple virtual hosts
location corresponding server directory level control block, you may have a plurality of

7. Detailed profile parameters

#user  nobody;
worker_processes  1;#配置 Nginx 的工作进程数, 一般设为 CPU 总核数或者总核数的两倍

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

#pid        logs/nginx.pid;


events {
    worker_connections  1024;#配置 Nginx 允许单个进程并发连接的最大请求数
}


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;#默认值为 on ,表示开启高效文件传输模式
    #tcp_nopush     on;

    #keepalive_timeout  0;#设置长连接超时时间(单位:秒)
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;#监听端口,默认监听 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 #http响应码              /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;
        }
        #location ~ /\.ht {
        #    deny  all; #访问权限控制,deny是拒绝,allow是允许
        #}

        
    }
}

 8.ngxin process design

A master process and a plurality of work processes composition, the main receiving process receives the client request, forwarded to the worker process to make good use of the computing power of multi-core CPU. When the administrator performs reload command to reload themselves straight, the main process will wait for the worker process to complete the work after the end of the work process, and then based on the new situation with a straight re-create the work process, to avoid the work process is interrupted. Since the whole process of the main process does not stop, so the case of missing client request will not occur

 

 

 

Guess you like

Origin blog.csdn.net/ly853602/article/details/92802725