性能優化-優化Nginx連接配接參數,調整連接配接逾時時間
worker_connections增加連接配接數,但不是意味着通過worker_connections增大了,就可以浪費,在一定程度上通過逾時時間控制,可以有效的節省連接配接數,不會造成資源浪費,即開源了又節流了
keepalive_timeout 60;
確定通訊雙方在一定時間内都沒有資料傳輸了, 就斷開連接配接
設定參數 keepalive_timeout 60; 作用:用戶端連接配接在伺服器端保持多久後退出
參數文法 keepalive_timeout 時間數(秒);
放置位置 http,server,location
client_header_timeout 15;
發送方放出請求資訊, 但接收方遲遲不作出響應
設定參數 client_header_timeout 15; 作用:設定讀取用戶端請求頭資料的逾時時間,如果超過這個時間用戶端還沒有發送完整的資料,伺服器端将傳回408錯誤,放置用戶端利用http協定進行攻擊
參數文法 client_header_timeout 時間數(秒);
放置位置 http,server

client_body_timeout 15
發送方發出主體資訊, 但接收方沒有正常處理
設定參數 client_body_timeout 15; 作用:設定讀取用戶端請求主體的逾時間
參數文法 client_body_timeout 時間數(秒);
放置位置 http,server,location
send_timeout 25;
服務端等待用戶端兩次請求的間隔時間
設定參數 send_timeout 25; 作用:設定服務端傳送HTTP響應資訊到用戶端的逾時間
參數文法 send_timeout 時間數(秒);
放置位置 http,server,location
配置以上參數
[root@web01 ~]# cat /application/nginx/conf/nginx.conf
worker_processes 2;
worker_cpu_affinity 0101 1010;
error_log logs/error.log;
#配置Nginx worker程序最大打開檔案數
worker_rlimit_nofile 65535;
user www www;
events {
#單個程序允許的用戶端最大連接配接數
worker_connections 20480;
#使用epoll模型
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
#sendfile on;
#keepalive_timeout 65;
#通路日志配置
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#虛拟主機
include /application/nginx/conf/extra/www.conf;
include /application/nginx/conf/extra/blog.conf;
include /application/nginx/conf/extra/bbs.conf;
include /application/nginx/conf/extra/edu.conf;
include /application/nginx/conf/extra/phpmyadmin.conf;
include /application/nginx/conf/extra/status.conf;
#nginx優化----------------------
#隐藏版本号
server_tokens on;
#優化伺服器域名的散清單大小
server_names_hash_bucket_size 64;
server_names_hash_max_size 2048;
#開啟高效檔案傳輸模式
sendfile on;
#減少網絡封包段數量
#tcp_nopush on;
#提高I/O性能
tcp_nodelay on;
#連接配接逾時 時間定義 預設秒 預設65秒
keepalive_timeout 60;
#讀取用戶端請求頭資料的逾時時間 預設秒 預設60秒
client_header_timeout 15;
#讀取用戶端請求主體的逾時時間 預設秒 預設60秒
client_body_timeout 15;
#響應用戶端的逾時時間 預設秒 預設60秒
send_timeout 25;
}