Nginx Configuration Detailed
#全局配置
#高层配置
User www-data# running users default configuration
Pid/var/run/nginx.pid; #端口号默认配置
Worker_processes 8; #定义了nginx对外提供web服务时的worker进程数
#最优值取决于许多因素, including (but not limited to) the number of CPU cores, the number of hard drives that store data, and the load pattern
#通常设置成和cpu的数量相等 (set to "Auto" will try to automatically detect it)
Worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; #将8个进程分配到8个cpu, of course, you can write more than one, Or assign a process to multiple CPUs
Worker_rlimit_nofile 200000; #更改worker进程的最大打开文件数限制
#如果没设置的话, this value is the limit of the operating system
#设置后你的操作系统和Nginx可以处理比 "Ulimit-a" more files, so set this value high so that Nginx will not have "too many open files" problem
#假如填写10240, when the total concurrency reaches 340,000, the process may exceed 10240, and a 502 error will be returned
#这个指令是指当一个nginx the maximum number of file descriptors opened by the process, the theoretical value should be the number of open files (ulimit-n) divided by the number of nginx processes, but the Nginx allocation request is not uniform, so it is best to keep the value of ulimit-n consistent
Events {
Worker_connections 102400; #设置可由一个worker进程同时打开的最大连接数
#如果设置了上面提到的worker_rlimit_nofile, we can set this value very high.
#重点: The maximum number of customers is also limited by the number of socket connections available to the system (~ 64K), so setting unrealistic high is no good
The maximum number of Connections #理论上每台nginx server is worker_processes*worker_connections
Multi_accept on; #告诉nginx收到一个新连接通知后接受尽可能多的连接
Use Epoll; #设置用于复用客户端线程的轮询方法
}
HTTP {
Server_tokens off; #并不会让nginx执行的速度更快, but it can turn off the Nginx version number in the error page, which is good for security
Sendfile on; #可以让sendfile () play a role
Tcp_nopush on; #告诉nginx在一个数据包里发送所有头文件 instead of sending one after another
Tcp_nodelay on; #告诉nginx不要缓存数据, but a section of the send-when you need to send data in a timely manner, you should set this property to the application, so that when sending a small piece of data information can not immediately get the return value
Access_log off; #设置nginx是否将存储访问日志. Turn off this option to make read disk IO operations faster (Aka,yolo)
Error_log/var/log/nginx/error.log Crit; #告诉nginx只能记录严重的错误
Keepalive_timeout 10; #给客户端分配keep-alive Link time-out. The server will close the link after this timeout period. We set it down so that Ngnix can keep working for a longer time.
Client_header_timeout 10; #设置请求头的超时时间. We can also lower this setting.
Client_body_timeout 10; #设置请求体的超时时间. We can also lower this setting.
Reset_timedout_connection on; #告诉nginx关闭不响应的客户端连接. This will release the memory space that the client occupies.
Send_timeout; #指定客户端的响应超时时间. This setting is not used for the entire forwarder, but between two client read operations. If during this time, the client does not read any data, Nginx will close the connection
Limit_conn_zone $binary _remote_addr z>The parameters of the shared memory #设置用于保存各种key (such as the current number of connections).
#5m就是5兆字节, this value should be set large enough to store (32K*5) 32byte states or (16K*5) 64byte states.
Limit_conn #为给定的key设置最大连接数. Here key is addr, we set the value is 100, that is to say we allow each IP address at most simultaneously open has 100 connection
Include/etc/nginx/mime.types; #只是一个在当前文件中包含另一个文件内容的指令. Here we use it to load a series of MIME types that will be used later
Default_type text/html; #设置文件使用的默认的MIME-type
CharSet UTF-8; #设置头文件中的默认的字符集
gzip on; #是告诉nginx采用gzip压缩的形式发送数据. This will reduce the amount of data we send
Gzip_disable "Msie6"; # Disables the gzip feature for the specified client. We set it to IE6 or lower to make our solution broadly compatible
# gzip_static on; #告诉nginx在压缩资源之前, find out if there are pre-gzip-processed resources
#这要求你预先压缩你的文件, allowing you to use the maximum compression ratio so that Nginx does not have to compress the files.
Gzip_proxied any; #允许或者禁止压缩基于请求和响应的响应流. We set it to any, which means that all requests will be compressed.
Gzip_min_length 1000; #设置对数据启用压缩的最少字节数. If a request is less than 1000 bytes,
#我们最好不要压缩它, because compressing these small data reduces the speed of all processes that handle this request
Gzip_comp_level 4; #设置数据的压缩等级. This level can be any number between 1-9, 9 is the slowest but the maximum compression ratio.
#我们设置为4, this is a more eclectic setup.
Gzip_buffers 8k;
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; #打开缓存的同时也指定了缓存最大数目, and the time of the cache.
#我们可以设置一个相对高的最大时间 so we can get rid of them after more than 20 seconds of inactivity.
Open_file_cache_valid 30s; #在open_file_cache中指定检测正确信息的间隔时间
Open_file_cache_min_uses 2; #定义了open_file_cache中指令参数不活动时间期间里最小的文件数
Open_file_cache_errors on;
include/etc/nginx/conf.d/*.conf;
include/etc/nginx/sites-enabled/*;
}
The above describes the Nginx high-performance configuration, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.