溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么在Nginx中實現(xiàn)timeout超時配置

發(fā)布時間:2021-05-25 17:26:39 來源:億速云 閱讀:147 作者:Leah 欄目:服務(wù)器

這篇文章給大家介紹怎么在Nginx中實現(xiàn)timeout超時配置,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

keepalive_timeout

HTTP 有一個 KeepAlive 模式,它告訴 webserver 在處理完一個請求后保持這個 TCP 連接的打開狀態(tài)。若接收到來自客戶端的其它請求,服務(wù)端會利用這個未被關(guān)閉的連接,而不需要再建立一個連接。

http keep-alive, 網(wǎng)頁的每一個請求都是HTTP (圖片, CSS等), 而打開HTTP 請求是要先建立TCP 連接, 而如果一個頁面每個請求都要打開及關(guān)閉一個TCP 連接就會做成資源的浪費. keepalive_timeout 就是當(dāng)一個HTTP 請求完成, 其TCP 連接會存留下來的時間, 如果這時有另一個HTTP 請求過來, 會複用這個TCP 連接, 如果再沒有新的請求過來, 才會關(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ù)至客戶端超時, 默認(rèn)60s, 如果連續(xù)的60s內(nèi)客戶端沒有收到1個字節(jié), 連接關(guān)閉

  • proxy_connect_timeout: nginx與upstream server的連接超時時間

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

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

so_timeout:

當(dāng)用戶跟SERVER開啟了TCP CONNECTION --> 一段長時間這個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.

關(guān)于怎么在Nginx中實現(xiàn)timeout超時配置就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI