Nginx timeout超時(shí)如何配置

keepalive_timeout

http 有一個(gè) keepalive 模式,它告訴 webserver 在處理完一個(gè)請(qǐng)求后保持這個(gè) tcp 連接的打開(kāi)狀態(tài)。若接收到來(lái)自客戶端的其它請(qǐng)求,服務(wù)端會(huì)利用這個(gè)未被關(guān)閉的連接,而不需要再建立一個(gè)連接。

http keep-alive, 網(wǎng)頁(yè)的每一個(gè)請(qǐng)求都是http (圖片, css等), 而打開(kāi)http 請(qǐng)求是要先建立tcp 連接, 而如果一個(gè)頁(yè)面每個(gè)請(qǐng)求都要打開(kāi)及關(guān)閉一個(gè)tcp 連接就會(huì)做成資源的浪費(fèi). keepalive_timeout 就是當(dāng)一個(gè)http 請(qǐng)求完成, 其tcp 連接會(huì)存留下來(lái)的時(shí)間, 如果這時(shí)有另一個(gè)http 請(qǐng)求過(guò)來(lái), 會(huì)複用這個(gè)tcp 連接, 如果再?zèng)]有新的請(qǐng)求過(guò)來(lái), 才會(huì)關(guān)閉其tcp連接

user?nginx; worker_processes?1; ? error_log?/var/log/nginx/error.log?warn; pid????/var/run/nginx.pid; ? ? events?{ ??worker_connections?1024; } ? ? http?{ ??include????/etc/nginx/mime.types; ??default_type?application/octet-stream; ? ??log_format?main?'$remote_addr?-?$remote_user?[$time_local]?"$request"?' ???????????'$status?$body_bytes_sent?"$http_referer"?' ???????????'"$http_user_agent"?"$http_x_forwarded_for"'; ? ??access_log?/var/log/nginx/access.log?main; ? ??sendfile????on; ??tcp_nopush???on; ??tcp_nodelay?on; ? ? ??keepalive_timeout?65; ??client_max_body_size?8192m; ? ??#gzip?on; ? ??#include?/etc/nginx/conf.d/*.conf; ? ? ? ??server?{ ?listen?80?so_keepalive=30m::; ?listen?443?default?ssl; ? ?ssl_certificate?/etc/nginx/ssl/server.crt; ?ssl_certificate_key?/etc/nginx/ssl/portalkey.key; ?#ssl_password_file?/etc/nginx/ssl/ssl.pass; ? ? ????ssl_session_timeout?5m; ????ssl_protocols?sslv2?sslv3?tlsv1; ????ssl_ciphers?high:!anull:!md5; ????ssl_prefer_server_ciphers?on; ? ?location?/?{ ?proxy_request_buffering?off; ?proxy_pass?http://127.0.0.1:8011/; ?proxy_connect_timeout????180; ????proxy_send_timeout?????180; ????proxy_read_timeout?????180; ????send_timeout??180; ?} ?location?/test1_url/?{ ?proxy_pass?http://127.0.0.1:8008/; ?proxy_connect_timeout????180; ????proxy_send_timeout?????180; ????proxy_read_timeout?????180; ????send_timeout??180; ?} ?location?/test2_url/?{ ?proxy_pass?http://127.0.0.1:3000/; ?proxy_connect_timeout????180; ????proxy_send_timeout?????180; ????proxy_read_timeout?????180; ????send_timeout??180; ?} ??} }

# 配置段: http,默認(rèn)75s

keepalive_timeout 60;

  • send_timeout?:發(fā)送數(shù)據(jù)至客戶端超時(shí), 默認(rèn)60s, 如果連續(xù)的60s內(nèi)客戶端沒(méi)有收到1個(gè)字節(jié), 連接關(guān)閉

  • proxy_connect_timeout: nginx與upstream server的連接超時(shí)時(shí)間

  • proxy_read_timeout: nginx接收upstream server數(shù)據(jù)超時(shí), 默認(rèn)60s, 如果連續(xù)的60s內(nèi)沒(méi)有收到1個(gè)字節(jié), 連接關(guān)閉

  • proxy_send_timeout: nginx發(fā)送數(shù)據(jù)至upstream server超時(shí), 默認(rèn)60s, 如果連續(xù)的60s內(nèi)沒(méi)有發(fā)送1個(gè)字節(jié), 連接關(guān)閉

so_timeout:

當(dāng)用戶跟server開(kāi)啟了tcp connection –> 一段長(zhǎng)時(shí)間這個(gè)connection 沒(méi)traffic (so_keepalive timeout) –> server 發(fā)出探測(cè)包看用戶是否還存在 –> 若探測(cè)包沒(méi)回, 則關(guān)閉tcp connection?

so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]
so_keepalive=30m::10 ??will?set?the?idle?timeout?(tcp_keepidle)?to?30?minutes,?leave?the?probe?interval?(tcp_keepintvl)?at?its?system?default,?and?set?the?probes?count?(tcp_keepcnt)?to?10?probes.

以上三個(gè)參數(shù)只能使用一個(gè),不能同時(shí)使用, 比如so_keepalive=on, so_keepalive=off或者so_keepalive=30s::(表示等待30s沒(méi)有數(shù)據(jù)報(bào)文發(fā)送探測(cè)報(bào)文)

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊6 分享
站長(zhǎng)的頭像-小浪學(xué)習(xí)網(wǎng)月度會(huì)員