1.性能優(yōu)化相關(guān)配置
1.work_process? number | auto?
worker進(jìn)程的數(shù)量;通常應(yīng)該為當(dāng)前主機(jī)的cpu核數(shù)
2.worker_cpu_affinity 【cpu mask】? 提高緩存命中率
cpu mask :? 00000001 : 0號(hào)cpu
? ? ? ? ? ? ? ? ? ? ? 00000010 : 1號(hào)cpu
? ? ? ? ? ? ? ? ? ? ? 1000000? : 8號(hào)cpu
worker_cpu_affinity? ?0001? 0100
3.worker_priority number? ?worker進(jìn)程的優(yōu)先級(jí)
Syntax:worker_priority?number;
Default:worker_priority 0;
Context:main
定義工作進(jìn)程的調(diào)度優(yōu)先級(jí),就像使用nice命令一樣:負(fù)數(shù)表示更高的優(yōu)先級(jí)。 允許范圍通常在-20到20之間變化。
4.worker_rlimit_nofile
worker進(jìn)程所能打開的文件數(shù)量上限 如65535? ?支持并發(fā)連接數(shù)
5. events
events {
? ? #worker_connections? 1024;
}
worker_connections? ??設(shè)置工作進(jìn)程可以打開的最大并發(fā)連接數(shù)? ?work_process *?worker_connections? = 最大并發(fā)數(shù)
use method?
指明并發(fā)連接連接請(qǐng)求的處理方法,默認(rèn)自動(dòng)選擇最優(yōu)方法
use epoll;
accept_mutex? on | off
如果啟用了accept_mutex,則工作進(jìn)程將依次接受新連接。 否則,將通知所有工作進(jìn)程有關(guān)新連接的信息,如果新連接的數(shù)量很少,則某些工作進(jìn)程可能只會(huì)浪費(fèi)系統(tǒng)資源。(一般情況下打開即可,off情況下可能突然喚醒所有work造成驚群)
調(diào)試定位選項(xiàng)
1.daemon?
Syntax:daemon?on?|?off;
Default:daemon on;
Context:main
是否以守護(hù)進(jìn)程方式運(yùn)行nginx
2.master_process??
Syntax:master_process?on?|?off;
Default:master_process on;
Context:main
是否以 master / worker 運(yùn)行進(jìn)程 默認(rèn)為master 啟動(dòng)后沒有worker進(jìn)程
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時(shí),延時(shí)發(fā)送,合并多個(gè)請(qǐng)求后再發(fā)送
默認(rèn)為on 不延遲發(fā)送
5.sendfile?
是否啟用sendfile ,內(nèi)核中封裝報(bào)文直接發(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
錯(cuò)誤也頁面返回到200? 跳到404.html
8.try_files
location /images/ {
? ? try_files $uri /images/default.gif;
}
按順序查詢文件是否存在返回第一個(gè)找到的文件或者文件夾,如果所有文件或者文件夾找不到,會(huì)內(nèi)部重定向到最后一個(gè)參數(shù),最后一個(gè)參數(shù)是回退uri必須存在否則會(huì)出現(xiàn)內(nèi)部500錯(cuò)誤
9.keepalive_timeout
Syntax:keepalive_timeout?timeout?[header_timeout];
Default:keepalive_timeout 75s;
Context:http,?server,?location
設(shè)置保存連接時(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.
在一次長鏈接上所允許請(qǐng)求資源的最大數(shù)量 默認(rèn)為100次
11.keepalive_disable
Syntax:keepalive_disable?none?|?browser?...;
Default:keepalive_disable msie6;
Context:http,?server,?location
對(duì)那種瀏覽器禁止長鏈接
12.send_timeout
Syntax:send_timeout?time;
Default:send_timeout 60s;
Context:http,?server,?location
向客戶端發(fā)送響應(yīng)報(bào)文超時(shí)時(shí)長此處指兩次寫操作之間的間隔時(shí)長,而非整個(gè)響應(yīng)過程的傳輸時(shí)長
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;? ?//允許這個(gè)主機(jī)
? ? 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