The Nginx server configuration file is fully parsed

  • 2020-05-14 05:34:28
  • OfStack


user www www; //  The users and groups used 
 
worker_processes 8; //  Specified number of work spawn processes ( 1 A is equal to the cpu Total audit or total audit 2 Times) 
 
error_log logs/nginx_error.log crit; //  Specify the path to the error log. The error logging level is selected as :debug,info,notice,warn,error,crit 
 
#error_log logs/error.log;
 
#error_log logs/error.log notice;
 
#error_log logs/error.log info;
 
 
pid     nginx.pid; //  The specified pid Where files are stored 
 
#pid    logs/nginx.pid;
 
 
worker_rlimit_nofile 65535; // 1 a nginx The maximum number of file descriptors a process can open. The theoretical value is the maximum number of files that can be opened ( system ulimit -n) with nginx Processes divide, but nginx Requests are not evenly distributed, so a sum is recommended here ulimit  Value remains 1 to 
 
 
events {
   
  use  epoll; //  Using the network I/O model ,Linux System recommendation epoll model ,FreeBSD System recommendation kqueue model 
  
  worker_connections 51200; //  The number of connections allowed 
}
 
#  set http The server , Leverage its reverse proxy functionality to provide load balancing support 
http {
   
  include    mime.types; //  set mime type , Type by mime.type File defines 
  default_type application/octet-stream;
   
   
  charset utf-8; //  Sets the character set to be used , if 1 Web sites have multiple character sets , Please don't set it , You should let the programmer in HTML Through the code Meta Label set 
   
  ssi on; //  The page is static 1 The big problem is that most of the page content needs to be cached if the login user accesses it statically, but the personal information that the user logs in is dynamic ,ssi Used to solve the page partial caching problem 
   
  ssi_silent_errors on; //  The default is off , it is processed after it is opened SSI No error message is printed when file error occurs :"[an error occurred while processing the directive]"
  
  ssi_types text/shtml; //  The default is ssi_types text/html So if you need to htm and html Support, then do not need to set this sentence if required shtml Support, you need to set 
 
  #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;
 
  #  Enable efficient file transfer mode, sendfile Directive specifies nginx Whether to call sendfile Function to output the file. For normal applications, set to on If used to download applications such as disk IO Heavy duty application, can be set to off To balance disk and network I/O Processing speed, reducing the load on the system , If the picture doesn't display properly change this to off
  sendfile    on;
 
  #tcp_nopush   on; //  Prevent network congestion 
 
  #tcp_nodelay on;
   
  # autoindex off; //  Open directory list access, appropriate download server, default shutdown 
   
  server_names_hash_bucket_size 128; //  server-named hash Table size 
   
  client_header_buffer_size 32k; //  Upload file size limit 
   
  large_client_header_buffers 4 32k; //  Set the request cache 
   
  client_max_body_size 300m; //  Set the request cache 
   
  # ( with php-fpm The relevant )  Optimized upload support , You can accelerate for the big POST  Request processing speed, including file upload. Optimization is achieved by writing the request body 1 A temporary file, and then fastcgi  The protocol is implemented by passing the file name instead of the request body 
  client_body_in_file_only clean;
 
  client_body_temp_path /dev/shm 1 2;
 
  #  This parameter is used when the setting is large firefox or ie submit 1 A less than 512K Image access will be normal , The annotation mode is twice the size of the operating system page, 8K or 16K  . 1 General submitted pictures are greater than 512K , the submitted content will be written to a temporary file without any problems. When directory access is revoked (autoindex off;) , if the submitted image is greater than 512K  Will return 500 Internal Server Error error 
  client_body_buffer_size 512k;
 
   
  proxy_connect_timeout  5; //  Timeout time for back-end server connections _ Initiate handshake wait response timeout ( Proxy connection timeout )
 
   
  proxy_read_timeout    60; //  After successful connection _ Wait for backend server response time _ It's already in the back end of the queue waiting for processing (how long it takes the back end server to process the request) 
   
  proxy_send_timeout    5; //  Backend server data return time _ This means that the back-end server has to transfer all the data within a specified time 
   
  proxy_buffer_size    16k; //  This instruction sets the buffer size , The number obtained from the proxy backend server 1 Part of the response content , I'll put it here , The response of the small header It's usually in this part of the response .( The buffer size to hold the user header information )
   
  proxy_buffers      4 64k; //  This instruction sets the size and number of buffers , The response content obtained from the proxied back-end server , I'm going to put it here .  By default ,1 The size of the buffer is equal to the memory page size , May be 4K May also be 8K, It depends on the platform 
   
  proxy_busy_buffers_size 128k; //  There are in busy The state of the buffer size You can't add it up proxy_busy_buffers_size , control is transmitted to the client simultaneously buffer The number of 
   
  proxy_temp_file_write_size 128k; // #  Temporary file write size 
   
  # nginx and cgi The timeout time between 
  fastcgi_connect_timeout 90; 
  fastcgi_send_timeout 90;
  fastcgi_read_timeout 90;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
 
  #  open gzip The compression 
  gzip on;
  gzip_min_length 1k;
  gzip_buffers   4 16k;
  #  right http/1.1 Protocol requests are compressed if a reverse proxy is used nginx And the back end upstream server The server is in use 1.0 Protocol communication 
  gzip_http_version 1.1;
  gzip_comp_level 9;
  gzip_types    text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
   
  # nginx Cache directory (in location You need coordination under the paragraph proxy_store on  Enable caching  include proxy.conf  Detailed rules for processing  
  if ( ! -e $request_filename) ) {proxy_pass http://192.168.10.10;}
  
  proxy_temp_path  /data/wwwroot/proxy_temp_dir;
 
  #proxy_cache_path /data/wwwroot/cache.hxage.com levels=1:2  keys_zone=cache.hxage.com:3000m inactive=1y max_size=80G;
  # Nginx  The internal redirection rule is activated when URL  Point to the 1 And at the end there is no" / "When, Nginx  It will do it internally 1 a 301  Redirection, there are two things that happen 
  # 1 , server_name_in_redirect on (default), URL  The redirection is: server_name  The first of 1 A domain name +  Directory name + / ; 
  # 2 , server_name_in_redirect off . URL  The redirection is: original URL  The domain name +  Directory name + /
  server_name_in_redirect off;
 
  server_tokens off;
 
  # sub filter
 
  # include sub_filter.conf;
 
  # null hostname
 
  server {
     listen 80 default;
     return 444;
     access_log off;
 }
server
{
    listen 5566;
    server_name localhost;
    index index.html index.htm index.shtml index.php;
    location ~ ^/status/
    {
        stub_status on;
        access_log off;
    }
}
#---------------- Vhost --------------------#
include vhost/*.conf;
}

The following is the section 1 nginx.conf configuration file on the aliyun host


user www www;
worker_processes auto;
 
error_log /alidata/log/nginx/error.log crit;
pid    /alidata/server/nginx/logs/nginx.pid;
 
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
 
events
{
 use epoll;
 worker_connections 65535;
}
 
 
http {
    include    mime.types;
    default_type application/octet-stream;
 
    #charset gb2312;
 
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
 
    sendfile on;
    tcp_nopush   on;
 
    keepalive_timeout 15;
 
    tcp_nodelay on;
 
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
 
    gzip on;
    gzip_min_length 1k;
    gzip_buffers   4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types    text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_disable msie6;
    #limit_zone crawler $binary_remote_addr 10m;
    log_format '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';
    include /alidata/server/nginx/conf/vhosts/*.conf;
}


Related articles: