Detailed explanation of nginx configuration file parameters

 
 # User running 
the User the WWW - the Data;     

# start the process, and usually set to equal the number of cpu 
worker_processes   1 ; 

# global error log and PID files 
error_log   / var / log / nginx / error.log; 
pid         / var / RUN / nginx. pid; 
    #Working 
 

mode and maximum number of connections 
events { use epoll; #epoll is a way of multiplexing IO (I / O Multiplexing), but only for Linux2.6 and above kernels, can greatly improve the performance of nginx 
    worker_connections 1024 ; #Maximum   number of concurrent connections for a single background worker process 
    # multi_accept on; 
} #Set 
 

http server, use its reverse proxy function to provide load balancing support 
http { #Set 
     mime type, type is mime.type file definition
    include        / etc / nginx / mime.types; 
    default_type application / octet- stream; #Set 
    log format 
    access_log     / var / log / nginx / access.log; 

    #sendfile directive specifies whether nginx calls the sendfile function (zero copy method) to output For common applications, 
    # must be set to on. If it is used to download applications such as disk IO heavy load applications, it can be set to off to balance the disk and network I / O processing speed and reduce the system uptime. 
    Sendfile on; 
    # ON tcp_nopush; 

    # connection time 
    #keepalive_timeout   0 ; 
    keepalive_timeout   65 ; 
    TCP_NODELAY ON; 
    
    # open gzip compression 
    gzip ON; 
    gzip_disable" MSIE [1-6] \. (?!. * SV1) " 
        #listening #define access using www.xx.com; 
    #Set 

    request buffer client_header_buffer_size 1k; 
    large_client_header_buffers   4 4k; 

    include /etc/nginx/conf.d / * .conf; 
    include / etc / nginx / sites-enabled / *; 
     #Set 

    load balancing server list upstream mysvr { 
    The #weigth parameter indicates the weight, and the higher the weight, the greater the probability of being assigned. #Squid 
    on this machine opens port 3128 
    server 192.168.8.1:3128 weight = 5; 
    server 192.168.8.2:80 weight = 1; 
    server 192.168. 8.3: 80 weight = 6; 
    } 


   server { 
        #listen 
    80 
        listen 80; server_name www.xx.com; #set 

        the access log of this virtual host 
        access_log logs / www.xx.com.access.log main; #default 

    request 
    location / { 
          root / root; #define the default website root directory location of the server 
          index index.php index.html index.htm ; 

          #Define the name of the index file on the homepage fastcgi_pass www.xx.com; 
         fastcgi_param SCRIPT_FILENAME $ document_root / $ fastcgi_script_name; 
          include / etc / nginx / fastcgi_params; 
        } 

    # define the error prompt page 
    error_page 500 502 503 504 /50x.html;   
        location = / 50x.html { 
        root / root; 
    } #Static 

    file, nginx handles 
    location ~ ^ / (images | javascript | js | css | flash | media | static) / { 
        root / var / www / virtual / htdocs; 
        #Expired for 30 days, static files are not updated very much, the expiration can be set larger, if it is updated frequently, it can be set smaller. 
        expires 30d;
    } 
    #PHP script requests are all forwarded to FastCGI processing. Use FastCGI default configuration. 
    Location ~ \ .php $ { 
        root / root; 
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME / home / www / www $ fastcgi_script_name; 
        fastcgi_params the include; 
    } 
    # Check Nginx state setting address 
    LOCATION / NginxStatus { 
        stub_status ON; 
        access_log ON; 
        auth_basic "NginxStatus"; 
        auth_basic_user_file the conf / the htpasswd; 
    } 
    # prohibit file access .htxxx 
    LOCATION ~ /\.ht { 
Nginx Detailed configuration file 
        deny all;
    } 
     
     } 

} 
#Run 

 user 
user www-data;     #Start the 

process, usually set to equal the number of CPU worker_processes 1; #Global 

error log and PID file 
error_log /var/log/nginx/error.log; 
pid / var / run /nginx.pid; #Working 
 

mode and maximum number of connections 
events { 
    use epoll; #epoll is a method in multiplexed IO (I / O Multiplexing), but only for Linux2.6 and above kernels, which can be greatly improved nginx performance 
    worker_connections 1024; #Maximum number of concurrent connections for a single background worker process 
    # multi_accept on; 
} #Set 
 

http server, use its reverse proxy function to provide load balancing support 
http { #Set 
     mime type, type by mime .type file definition 
    include /etc/nginx/mime.types; 
    default_type application / octet-stream; #set 
    log format 
    access_log /var/log/nginx/access.log;

    The #sendfile instruction specifies whether nginx calls the sendfile function (zero copy method) to output the file. For ordinary applications, 
    # must be set to on. If it is used for downloading and other application disk IO heavy-load applications, it can be set to off to balance the disk and Network I / O processing speed reduces the system's uptime. 
    Sendfile 
    on; #tcp_nopush on; #Connection 

    timeout time # 
    keepalive_timeout 
    0; keepalive_timeout 65; 
    tcp_nodelay 
    on; 
    #Turn 
    
    on gzip compression gzip on; gzip_disable "MSIE [1-6] \. (?!. * SVl) "; 

    # setting request buffer 
    client_header_buffer_size 1K; 
    large_client_header_buffers 4K. 4; 

    the include /etc/nginx/conf.d/*.conf; 
    the include / etc / Nginx / sites-Enabled / *; 

    # set Load balancing server list 
    # Squid on the machine opens port 3128 
     #set upstream mysvr {
    The #weigth parameter indicates the weight. The higher the greater the chance of being assigned. 
         fastcgi_param SCRIPT_FILENAME $ document_root / $ fastcgi_script_name;
    server 192.168.8.1:3128 weight = 5; 
    server 192.168.8.2:80 weight = 1; 
    server 192.168.8.3:80 weight = 6; 
    } 


   server { 
        #listening 
    80 port 
        listen 80; #define access using www.xx.com 
        server_name www.xx.com; #Set 

        the access log of this virtual host 
        access_log logs / www.xx.com.access.log main; #Default 

    request 
    location / { 
          root / root; #Define the default website root directory location 
          index of the server index.php index.html index.htm; 

          #Define the name of the index file on the homepage fastcgi_pass www.xx.com; 
          include / etc / nginx / fastcgi_params; 
        } 

    # Define the error prompt page 
    error_page 500 502 503 504 /50x.html;   
        location = /50x.html { 
        root / root; 
    } #static 

    file, nginx handles 
    location ~ ^ / (images | javascript | js | css | flash | media | static) / { 
        root / var / www / virtual / htdocs; 
        #Expired for 30 days, static files are not updated very much, the expiration can be set larger, and if updated frequently, it can be set smaller. 
        expires 30d; 
    } 
    #PHP script requests are all forwarded to FastCGI. Use FastCGI default configuration. 
    location ~ \ .php $ { 
        root / root; 
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME / home / www / www $ fastcgi_script_name; 
        include fastcgi_params; 
    }
        #Set 
    the address to view Nginx status  
    #Set location / NginxStatus { 
        stub_status on;
        access_log on; auth_basic "NginxStatus"; 
        auth_basic_user_file conf / htpasswd; 
    } 
    #Prohibit access to .htxxx files 
    location ~ /\.ht { 
        deny all; 
    } 
     
     } 

}

 

Guess you like

Origin www.cnblogs.com/LuckWJL/p/12677053.html