1. nginx.conf File:
User Username #指定允许ninx的用户名
Worker_processes 11; #一般为物理核心数-1,
Worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000; #绑定nginx允许的CPU核心
Error_log/var/log/nginx/error1.log; #nginx错误日志的保存路径
Pid/path/to/pidfile_name; Specify the path of the PID file, compile the time can be specified, the edge can also be re-specified in the configuration file, is the necessary instructions
Worker_rlimit_nofile #指定一个worker进程所能够打开的最大文件句柄数;
Worker_rlimit_sigpending #; Sets the number of signals each user can send to the worker process;
Events {
Worker_connections 2048; #每个woker进程能打开的最大连接数
Multi_accept on; #是否允许一次性地响应多个用户请求
Use Epoll; #定义使用的事件模型, it is recommended to let nginx automatically select;
}
for debugging, locating problems: Use only when debugging Nginx
1,Daemon[on|off]
The default is on, which is set to offwhen debugging , so that all information is output directly to the debug console.
2,Master_processon|off
The default is on, while debugging can turn master off to start only one worker, easy to locate the problem. That is to run Nginx in woker mode
3,error_log/path/to/error_log level;
error log file and its level, default is error level, debug level can be used when debugging , but requires that the debug feature must be enabled at compile time using --with-debug ;
Server_tokens off; #隐藏错误页面的nginx版本信息
Keepalive_timeout time; The timeout for keeping the connection is long; default is 75 seconds;
Keepalive_requests N; The maximum number of requests that are allowed to be hosted on a single long connection;
keepalive_disable [Msie6 | safari | None] prohibit the use of long connections to the specified browser;
Tcp_nodelay On|off #发送响应的超时时长
Client_header_timeout time; #即读取http请求首部的超时时长, the default is 60 seconds, the link bad situation can be adjusted a little bit
Client_body_timeout time; #读取http请求包体的超时时长默认60秒, if the link is bad, you can turn it down a little bit.
Send_timeout time; # sent to the user but the user receives the timeout time, the response time to send the timeout length
Restrictions on client requests:
Limit_exceptmethod ...
Allows the use of methods other than those written here, which is not available in the
Specifies access control for methods other than the scope;
Limit_exceptget {
ALLOW172.16.0.0/16;
Denyall;
}
2,client_max_body_sizesize;
The maximum value of the HTTP request packet, which is often used to limit the maximum package that the client can request , and is detected by the Content-length in the request header to avoid useless transmission;
3,limit_ratespeed;
limit the number of bytes that the client transmits bytes per second; The default is 0, which means there is no limit;
4,limit_rate_aftertime;
When the Nginx sends the response message to the customer, if the time exceeds the length specified here, then the subsequent sending process starts the speed limit;
Optimization of file operations:
1,Sendfileon|off
Whether the Sendfile function is enabled ;
2.AIO On|off
Whether the AIO feature is enabled ;
3,open_file_cachemax=n [Inactive=time]|off
Whether to open the file cache function;
Max: The maximum value of the cache entry , which will be replaced by the LRU algorithm when full;
Inactive: A cache entry is not accessed for a specified length of time and is automatically deleted; default is 60s;
The cached information includes:
File handle, file size, and last modified time;
The directory structure that has been opened;
No information was found or not accessible;
4,Open_file_cache_errorson|off
Whether the cache file cannot be found or does not have permission to access the relevant information;
5,open_file_cache_validtime;
How often do you check if the entries in the cache exceed the inactive duration, and the default is 60s;
6,open_file_cache_min_use#;
The time specified in inactive is accessed over the specified number of times and is not deleted;
Special handling of client requests:
1,Ignore_invalid_headerson|off
whether to ignore the illegal http header; Off means that the first refusal to respond to a non-compliant header in the request will be used only for server and http;
2,Log_not_foundon|off
The information that is not found in the file is also recorded in the error log;
3,resolveraddress;
Specifies the DNS server address used by Nginx;
4,resover_timeouttime;
Specify DNS Resolution Timeout length, default is 30s;
5,Server_tokenson|off;
whether to display the version number of Nginx in the error page;
Memory and disk resource allocation:
1,Client_body_in_file_onlyon|clean|off
whether the packet of HTTP is stored in a disk file, off means no storage, and non- off means that it is stored, even if the package size is 0, A disk file is created; Indicates that the package body file will not be deleted after the request ends, andclean indicates that it will be deleted;
2,Client_body_in_single_bufferon|off;
whether the packet of HTTP is stored in buffer , the default is off;
3,cleint_body_buffer_sizesize; # default is 8k
Nginx receives the memory buffer size of the HTTP packet body;
4,client_body_temp_pathdir-path [Level1 [Level2 [LEVEL3]]; # is a directory folder, can be a multi-level directory, multi-level directory can prevent too many files in one directory, resulting in slow retrieval
the temporary directory where the HTTP package is stored;
CLIENT_BODY_TEMP_PATH/VAR/TMP/CLIENT/1 2
1 1 1 -level sub-directories, which are 1x16 equal to the 1 -level subdirectory of the three -in-one system
2 2 2 -level sub-directories, with 16x16 equal to the two-level subdirectory of the three -in-one system
5,client_header_buffer_sizesize;
The buffer size allocated when receiving the header portion of the HTTP message requested by the user under normal circumstances ; default is 1k;
6,large_client_header_buffersnumber size;
Storage Super Large The size and number of memory buffer for Http request header ;
7,connection_pool_sizesize;
Nginx allocates a memory pool for each successful TCP connection, which is used to set the initial size of this memory pool;
8,request_pool_sizesize;
Nginx allocates a pool of memory for each HTTP request, which is used to set the initial size of this memory pool; The default is 4k;
File transfer and compression:
Include/etc/nginx/mime.types; contains the contents of another file in the current file, which can be/opt/nginx.d/*.conf
Default_type text/html; Sets the default Mime-type used by the file.
CharSet UTF-8; Set the default character set in the header file
gzip on; tell Nginx to use gzip compression to send data, which will reduce the amount of data we send.
Gzip_disable "Msie6"; Disable the gzip feature for the specified client
# gzip_static on; gzip_static tells Nginx to look for pre-gzip-processed resources before compressing the resource, allowing you to use the highest compression ratio so that Nginx does not have to compress the files again.
Gzip_proxied any permits or suppresses the compression of response streams based on requests and responses. We set it to any, which means that all requests will be compressed.
gzip_min_length; sets the minimum number of bytes to enable compression on the data. If a request is less than 1000 bytes, we'd better not compress it, because compressing these small data reduces the speed of all processes that handle this request.
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x avascript text/xml application/xml application/xml+rss text/javascript; set the data format that you want to compress.
For example, set Nginx:
User Www-data;
Pid/var/run/nginx.pid;
Worker_processes Auto;
Worker_rlimit_nofile 100000;
Events {
Worker_connections 2048;
Multi_accept on;
Use Epoll;
}
HTTP {
Server_tokens off;
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Access_log off;
Error_log/var/log/nginx/error.log Crit;
Keepalive_timeout 10;
Client_header_timeout 10;
Client_body_timeout 10;
Reset_timedout_connection on;
Send_timeout 10;
Limit_conn_zone $binary _remote_addr zone=addr:5m;
Limit_conn addr 100;
Include/etc/nginx/mime.types;
Default_type text/html;
CharSet UTF-8;
gzip on;
Gzip_disable "Msie6";
Gzip_proxied any;
Gzip_min_length 1000;
Gzip_comp_level 6;
Gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml Application/xml+rss Text/javascript;
Open_file_cache max=100000 inactive=20s;
Open_file_cache_valid 30s;
Open_file_cache_min_uses 2;
Open_file_cache_errors on;
include/etc/nginx/conf.d/*.conf;
include/etc/nginx/sites-enabled/*;
}
This article is from the "Linux" blog, so be sure to keep this source http://zhangshijie.blog.51cto.com/806066/1642553
nginx.conf configuration file