worker_process 4;
worker_priority 0; 進程的靜態優先級,范圍在-20~19,-20為最高優先級
worker_cpu_affinity 1000 0100 0010 0001; 配置每個worker進程使用哪個cpu,使得不會互相搶cpu
worker_rlimit_nofile 100000; 更改worker進程的最大打開文件數限制
worker_connections 2048;
multi_accept on; 一次accept一個新連接,or 一次accept所有的新連接
use epoll;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 8k;
client_max_body_size 10m;
client_body_buffer_size 512k;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
sendfile on; 立即將數據從磁盤讀到OS緩存。這種拷貝是在內核完成的
tcp_nopush on; 告訴nginx在一個數據包里發送所有頭文件,而不一個接一個的發送。
tcp_nodelay on; 告訴nginx不要緩存數據,而是一段一段的發送--當需要及時發送數據時
keepalive_timeout 65;
gzip on;
gzip_comp_level 4 ; 設置數據的壓縮等級 1-9之間的任意數值,設置為4,這是一個比較折中的設置
gzip_min_length 1k;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
access_log off; 設置nginx是否將存儲訪問日志。關閉這個選項可以讓讀取磁盤IO操作更快(aka,YOLO)
error_log 告訴nginx只能記錄嚴重的錯誤:
# cache informations about file descriptors, frequently accessed files
# can boost performance, but you need to test those values
open_file_cache max=100000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
open_file_cache 打開緩存的同時也指定了緩存最大數目,以及緩存的時間。我們可以設置一個相對高的最大時間,這樣我們可以在它們不活動超過20秒后清除掉。
open_file_cache_valid 在open_file_cache中指定檢測正確信息的間隔時間。
open_file_cache_min_uses 定義了open_file_cache中指令參數不活動時間期間里最小的文件數。
open_file_cache_errors 指定了當搜索一個文件時是否緩存錯誤信息,也包括再次給配置中添加文件。我們也包括了服務器模塊,這些是在不同文件中定義的。如果你的服務器模塊不在這些位置,你就得修改這一行來指定正確的位置。