1.性能優(yōu)化相關(guān)配置
1.work_process? number | auto?
worker進程的數(shù)量牛哺;通常應(yīng)該為當(dāng)前主機的cpu核數(shù)
2.worker_cpu_affinity 【cpu mask】? 提高緩存命中率
cpu mask :? 00000001 : 0號cpu
? ? ? ? ? ? ? ? ? ? ? 00000010 : 1號cpu
? ? ? ? ? ? ? ? ? ? ? 1000000? : 8號cpu
worker_cpu_affinity? ?0001? 0100
3.worker_priority number? ?worker進程的優(yōu)先級
Syntax:worker_priority?number;
Default:worker_priority 0;
Context:main
定義工作進程的調(diào)度優(yōu)先級蝙泼,就像使用nice命令一樣:負(fù)數(shù)表示更高的優(yōu)先級忧侧。 允許范圍通常在-20到20之間變化。
4.worker_rlimit_nofile
worker進程所能打開的文件數(shù)量上限 如65535? ?支持并發(fā)連接數(shù)
5. events
events {
? ? #worker_connections? 1024;
}
worker_connections? ??設(shè)置工作進程可以打開的最大并發(fā)連接數(shù)? ?work_process *?worker_connections? = 最大并發(fā)數(shù)
use method?
指明并發(fā)連接連接請求的處理方法,默認(rèn)自動選擇最優(yōu)方法
use epoll;
accept_mutex? on | off
如果啟用了accept_mutex,則工作進程將依次接受新連接。 否則凡资,將通知所有工作進程有關(guān)新連接的信息,如果新連接的數(shù)量很少谬运,則某些工作進程可能只會浪費系統(tǒng)資源隙赁。(一般情況下打開即可,off情況下可能突然喚醒所有work造成驚群)
調(diào)試定位選項
1.daemon?
Syntax:daemon?on?|?off;
Default:daemon on;
Context:main
是否以守護進程方式運行nginx
2.master_process??
Syntax:master_process?on?|?off;
Default:master_process on;
Context:main
是否以 master / worker 運行進程 默認(rèn)為master 啟動后沒有worker進程
3.error_log
Syntax:error_log?file?[level];
Default:error_log logs/error.log error;
Context:main,?http,?mail,?stream,?server,?location
http 模塊?ngx_http_core_module
http {
? ? server {
? ? ?1.? ?listen?address? [:port] [default_server] ;? 監(jiān)聽端口路徑
? ? ?2.? ?server_name? www.baidu.com;? 網(wǎng)站名稱
? ? ?3.? ?root /PATH/梆暖; 根目錄
????}
}
?4. tcp_nodelay
Syntax:tcp_nodelay?on?|?off;
Default:
tcp_nodelay on;
Context:http,?server,?location
在keepalived模式下的連接是否啟用
tcp_nodelay? 當(dāng)為off時伞访,延時發(fā)送,合并多個請求后再發(fā)送
默認(rèn)為on 不延遲發(fā)送
5.sendfile?
是否啟用sendfile 轰驳,內(nèi)核中封裝報文直接發(fā)送 默認(rèn)為off
普通read操作
硬盤—>內(nèi)核緩沖區(qū)—>用戶緩沖區(qū)—>內(nèi)核socket緩沖區(qū)—>協(xié)議引擎
使用sendfile
硬盤—>內(nèi)核緩沖區(qū)—>內(nèi)核socket緩沖區(qū)—>協(xié)議引擎
默認(rèn)為off
6.server_tokens
Syntax:server_tokens?on?|?off?|?build?|?string;
Default:server_tokens on;
Context:http,?server,?location
是否在響應(yīng)的server 顯示 nginx 版本
7.alias
目錄別名?
8.error_page?
error_page 404 = 200 /404.html
錯誤也頁面返回到200? 跳到404.html
8.try_files
location /images/ {
? ? try_files $uri /images/default.gif;
}
按順序查詢文件是否存在返回第一個找到的文件或者文件夾厚掷,如果所有文件或者文件夾找不到,會內(nèi)部重定向到最后一個參數(shù)级解,最后一個參數(shù)是回退uri必須存在否則會出現(xiàn)內(nèi)部500錯誤
9.keepalive_timeout
Syntax:keepalive_timeout?timeout?[header_timeout];
Default:keepalive_timeout 75s;
Context:http,?server,?location
設(shè)置保存連接時長冒黑,0表示禁止長鏈接 ,默認(rèn)為75秒
10.keepalive_requests
Syntax:keepalive_requests?number;
Default:keepalive_requests 100;
Context:http,?server,?location
This directive appeared in version 0.8.0.
在一次長鏈接上所允許請求資源的最大數(shù)量 默認(rèn)為100次
11.keepalive_disable
Syntax:keepalive_disable?none?|?browser?...;
Default:keepalive_disable msie6;
Context:http,?server,?location
對那種瀏覽器禁止長鏈接
12.send_timeout
Syntax:send_timeout?time;
Default:send_timeout 60s;
Context:http,?server,?location
向客戶端發(fā)送響應(yīng)報文超時時長此處指兩次寫操作之間的間隔時長勤哗,而非整個響應(yīng)過程的傳輸時長
13?limit_rate
Syntax:limit_rate?rate;
Default:
limit_rate 0;
Context:http,?server,?location,?if in location
限制給客戶端傳輸速率
14?limit_except
Syntax:limit_except?method?... { ... }
Default:—
Context:location
limit_except GET {
? ? allow 192.168.1.0/32;? ?//允許這個主機
? ? deny? all;? ?//其他不允許
}
15.aio
Syntax:aio?on?|?off?|?threads[=pool];
Default:aio off;
Context:http,?server,?location
This directive appeared in version 0.8.11.
異步IO
16