nginx使用proxy模塊時,默認的讀取超時時間是60s。瀏覽器
一、請求超時服務器
http { include mime.types; server_names_hash_bucket_size 512; default_type application/octet-stream; sendfile on;
keepalive_timeout 65; #保持 tcp_nodelay on; client_header_timeout 15; client_body_timeout 15; send_timeout 25; include vhosts/*.conf; }
二、後端服務器處理請求的時間設置(頁面等待服務器響應時間)app
location / { ... proxy_read_timeout 150; # 秒 ... }
nginx經常使用的超時配置說明tcp
client_header_timeoutpost
語法 client_header_timeout time
默認值 60s
上下文 http server
說明 指定等待client發送一個請求頭的超時時間(例如:GET / HTTP/1.1).僅當在一次read中,沒有收到請求頭,纔會算成超時。若是在超時時間內,client沒發送任何東西,nginx返回HTTP狀態碼408(「Request timed out」)
client_body_timeout
語法 client_body_timeout time
默認值 60s
上下文 http server location
說明 該指令設置請求體(request body)的讀超時時間。僅當在一次readstep中,沒有獲得請求體,就會設爲超時。超時後,nginx返回HTTP狀態碼408(「Request timed out」)
keepalive_timeout
語法 keepalive_timeout timeout [ header_timeout ]
默認值 75s
上下文 http server location
說明 第一個參數指定了與client的keep-alive鏈接超時時間。服務器將會在這個時間後關閉鏈接。可選的第二個參數指定了在響應頭Keep-Alive: timeout=time中的time值。這個頭可以讓一些瀏覽器主動關閉鏈接,這樣服務器就沒必要要去關閉鏈接了。沒有這個參數,nginx不會發送Keep-Alive響應頭(儘管並非由這個頭來決定鏈接是否「keep-alive」)
兩個參數的值可並不相同
- 注意不一樣瀏覽器怎麼處理「keep-alive」頭
- MSIE和Opera忽略掉"Keep-Alive: timeout=<N>" header.
- MSIE保持鏈接大約60-65秒,而後發送TCP RST
- Opera永久保持長鏈接
- Mozilla keeps the connection alive for N plus about 1-10 seconds.
- Konqueror保持長鏈接N秒
lingering_timeout
語法 lingering_timeout time
默認值 5s
上下文 http server location
說明 lingering_close生效後,在關閉鏈接前,會檢測是否有用戶發送的數據到達服務器,若是超過lingering_timeout時間後尚未數據可讀,就直接關閉鏈接;不然,必須在讀取完鏈接緩衝區上的數據並丟棄掉後纔會關閉鏈接。
resolver_timeout
語法 resolver_timeout time
默認值 30s
上下文 http server location
說明 該指令設置DNS解析超時時間
proxy_connect_timeout
語法 proxy_connect_timeout time
默認值 60s
上下文 http server location
說明 該指令設置與upstream server的鏈接超時時間,有必要記住,這個超時不能超過75秒。
這個不是等待後端返回頁面的時間,那是由proxy_read_timeout聲明的。若是你的upstream服務器起來了,可是hanging住了(例如,沒有足夠的線程處理請求,因此把你的請求放到請求池裏稍後處理),那麼這個聲明是沒有用的,因爲與upstream服務器的鏈接已經創建了。
proxy_read_timeout
語法 proxy_read_timeout time
默認值 60s
上下文 http server location
說明 該指令設置與代理服務器的讀超時時間。它決定了nginx會等待多長時間來得到請求的響應。這個時間不是得到整個response的時間,而是兩次reading操做的時間。
proxy_send_timeout
語法 proxy_send_timeout time
默認值 60s
上下文 http server location
說明 這個指定設置了發送請求給upstream服務器的超時時間。超時設置不是爲了整個發送期間,而是在兩次write操做期間。若是超時後,upstream沒有收到新的數據,nginx會關閉鏈接
proxy_upstream_fail_timeout(fail_timeout)
語法 server address [fail_timeout=30s]默認值 10s上下文 upstream說明 Upstream模塊下 server指令的參數,設置了某一個upstream後端失敗了指定次數(max_fails)後,該後端不可操做的時間,默認爲10秒