目录
worker_processes
work_cpu_affinity
worker_rlimit_nofile
events模块
1、use method;
2、worker_connections
3、multi_accept
http模块
1、server_names_hash_bucket_size
4、client_max_body_size
6、client_body_timeout
7、send_timeout
8、sendfile
9、tcp_nopush
10、tcp_nodelay
11、keepalive_timeout
12、server_tokens
13、limit_conn_zone
14、limit_conn
15、limit_conn_log_level
16、gzip
17、gzip_min_length
18、gzip_comp_level
19、gzip_buffers
20、gzip_types
21、gzip_http_version (1.0|1.1)
22、gzip_proxied
23、gzip_vary
24、gzip_disable
25、proxy_temp_path
26、proxy_cache_path
27、client_body_buffer_size
28、proxy_connect_timeout (default 60s)
29、proxy_read_timeout (default 60s)
30、proxy_send_timeout (default 60s)
31、proxy_buffer_size
32、proxy_buffers
33、proxy_busy_buffers_size
34、proxy_temp_file_write_size
35、proxy_next_upstream
EXAMPLE 基于上述 我配置的简单的nginx.conf 优化之后的 web代理配置:
worker_processes
工作进程数,操作系统启动多少个工作进程运行Nginx。注意是工作进程,不是有多少个nginx工程。在Nginx运行的时候,会启动两种进程,一种是主进程master process;一种是工作进程worker process。worker process。主进程负责监控端口,协调工作进程的工作状态,分配工作任务,工作进程负责进行任务处理。一般这个参数要和操作系统的CPU内核数成倍,(当值为 auto 时,nginx会自己决定工作进程数量)
下面是nginx官网原话:
Syntax: worker_processes number | auto;
Default: worker_processes 1;
Context: main Defines the number of worker processes. The optimal value depends on many factors including (but not limited to) the number of CPU cores, the number of hard disk drives that store data, and load pattern. When one is in doubt, setting it to the number of available CPU cores would be a good start (the value “auto” will try to autodetect it). The auto parameter is supported starting from versions 1.3.8 and 1.2.5.
网上寻找的一些经验总结:
- 一般设置为1就足够了,可以把连接数设置的很大,比如65535。
- 如果有SSL,gzip等比较消耗CPU资源的工作,而且CPU是多核的话,可以把值设置为和CPU核数一样。
- 如果有很多静态文件而且它们的总大小超过内存大小,那么可以增加工作进程来充分利用I/O带宽。
- 如果要开多个工作进程,最好是CPU核数的1~2倍。正常情况下,不要太多,因为工作进程太多会影响nginx主进程调度。
- worker_processes最多开启8个,8个以上性能提升不会再提升了,而且稳定性变得更低,所以8个进程够用了。
work_cpu_affinity
Nginx默认没有开启利用多核CPU,我们可以通过增加worker_cpu_affinity配置参数来充分利用多核CPU。CPU是任务处理,计算最关键的资源,CPU核越多,性