本文小編為大家詳細(xì)介紹“Nginx timeout超時(shí)如何配置”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“Nginx timeout超時(shí)如何配置”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識(shí)吧。
創(chuàng)新互聯(lián)是專業(yè)的永勝網(wǎng)站建設(shè)公司,永勝接單;提供成都做網(wǎng)站、網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行永勝網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
keepalive_timeout
http 有一個(gè) keepalive 模式,它告訴 webserver 在處理完一個(gè)請求后保持這個(gè) tcp 連接的打開狀態(tài)。若接收到來自客戶端的其它請求,服務(wù)端會(huì)利用這個(gè)未被關(guān)閉的連接,而不需要再建立一個(gè)連接。
http keep-alive, 網(wǎng)頁的每一個(gè)請求都是http (圖片, css等), 而打開http 請求是要先建立tcp 連接, 而如果一個(gè)頁面每個(gè)請求都要打開及關(guān)閉一個(gè)tcp 連接就會(huì)做成資源的浪費(fèi). keepalive_timeout 就是當(dāng)一個(gè)http 請求完成, 其tcp 連接會(huì)存留下來的時(shí)間, 如果這時(shí)有另一個(gè)http 請求過來, 會(huì)複用這個(gè)tcp 連接, 如果再?zèng)]有新的請求過來, 才會(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)客戶端沒有收到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)沒有收到1個(gè)字節(jié), 連接關(guān)閉
proxy_send_timeout: nginx發(fā)送數(shù)據(jù)至upstream server超時(shí), 默認(rèn)60s, 如果連續(xù)的60s內(nèi)沒有發(fā)送1個(gè)字節(jié), 連接關(guān)閉
so_timeout:
當(dāng)用戶跟server開啟了tcp connection --> 一段長時(shí)間這個(gè)connection 沒traffic (so_keepalive timeout) --> server 發(fā)出探測包看用戶是否還存在 --> 若探測包沒回, 則關(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沒有數(shù)據(jù)報(bào)文發(fā)送探測報(bào)文)
讀到這里,這篇“Nginx timeout超時(shí)如何配置”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。