nginx (2), nginx common configuration

#user  nobody;
error_log  logs/error.log  info; 
pid        logs/nginx.pid;
1、user  nobody:
Define the user and user group that Nginx runs as

2、error_log  logs/error.log  info:
Global error log definition type, [ debug | info | notice | warn | error | crit ]

3、pid        logs/nginx.pid; :
process pid file
 
worker_processes  auto;
worker_rlimit_nofile 65535;
1、worker_processes:
The number of nginx processes, it is recommended to set it to the total number of CPU cores of the current host, or set the automatic configuration auto


2 、 worker_rlimit_nofile 65535 :
The maximum number of file descriptors opened by an nginx process
The theoretical value should be the maximum number of open files in the system (the value of ulimit -n in the system) divided by the number of nginx processes, but nginx allocates requests unevenly, so it is recommended to keep the value of ulimit -n consistent.
Now under the Linux 2.6 kernel, the number of open files is 65535, and the worker_rlimit_nofile should be filled with 65535 accordingly.
 
#Working mode and connection limit
events{
   use epoll;
   worker_connections 65535;
1、  use epoll :
Refer to the event model, use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; The epoll model is a high-performance network I/O model in the Linux kernel version 2.6 and above. If running on FreeBSD, use the kqueue model .

2、worker_connections 65535
The maximum number of connections for a single process.
The maximum number of connections = the number of connections * the number of processes, if it is a proxy backend server, it should be divided by 2.
}
#httpserver
http {
    include       mime.types;                           
    default_type  application/octet-stream; 
1、include       mime.types:
File extension and file type mapping table

2、default_type  application/octet-stream;
Default file type
 
    #access_log  logs/access.log  main; 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
1、access_log  logs/access.log  main
Sets whether nginx will store access logs. Turning off this option can make read disk IO operations faster


2. Log format settings
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    sendfile        on; 
    #tcp_nopush     on;
    keepalive_timeout  65;
1、sendfile        on;  
Enable efficient file transfer mode. The sendfile instruction specifies whether nginx calls the sendfile function to output files. For common applications, set it to on. If it is used for applications with heavy disk IO load such as downloading, it can be set to off to balance the processing speed of disk and network I/O and reduce the load of the system. Note: If the picture is not displayed properly, change this to off.
    
2、tcp_nopush     on;
prevent network congestion

3、keepalive_timeout  65;
Connection timeout, in seconds
 
   #gzip on; 
#gzip module settings
1. gzip on; #Enable gzip compression output
2. gzip_min_length 1k; #Minimum compressed file size
3. gzip_buffers 4 16k; #Compression buffer
4. gzip_http_version 1.0; #Compression version (default 1.1, if the front end is squid2.5, please use 1.0)
5. gzip_comp_level 2; #Compression level
6、gzip_types text/plain application/x-javascript text/css application/xml;
   #Compression type, textml is already included by default, so there is no need to write it below, and there will be no problem in writing it, but there will be a warn.
7、gzip_vary on;
 
    #define virtual machine
    server {
        listen       80;
        server_name  localhost;
        charset utf-8;
1, listen 80; # listen port
2. server_name localhost; #Define the domain name
3, charset utf-8; # character set
 
       #resource location
        location / {
            #Location root directory
            root   html;
            index  index.html;
        }
        
        #define some 404,5xx pages
        #error_page  404              /404.html;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        #Image cache time setting
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
                 expires 10d;
        }
        #JS and CSS cache time settings
        location ~ .*.(js|css)?$ {
           expires 1h;
       }
    }
}
 
References:
http://www.cnblogs.com/nixi8/p/4871057.html
http://www.chinaz.com/web/2015/0424/401323_2.shtml
http://www.nginx.cn/76.html
http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html
 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326223490&siteId=291194637