怎么在Nginx中配置timeout超時-創(chuàng)新互聯(lián)

怎么在Nginx中配置timeout超時?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于成都網(wǎng)站設計、成都網(wǎng)站建設、陜州網(wǎng)絡推廣、微信平臺小程序開發(fā)、陜州網(wǎng)絡營銷、陜州企業(yè)策劃、陜州品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們大的嘉獎;成都創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供陜州建站搭建服務,24小時服務熱線:18982081108,官方網(wǎng)址:muchs.cn

keepalive_timeout

HTTP 是一種無狀態(tài)協(xié)議,客戶端向服務器發(fā)送一個 TCP 請求,服務端響應完畢后斷開連接。

如果客戶端向服務器發(fā)送多個請求,每個請求都要建立各自獨立的連接以傳輸數(shù)據(jù)。

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

KeepAlive 在一段時間內保持打開狀態(tài),它們會在這段時間內占用資源。占用過多就會影響性能。

Nginx 使用 keepalive_timeout 來指定 KeepAlive 的超時時間(timeout)。指定每個 TCP 連接最多可以保持多長時間。Nginx 的默認值是 75 秒,有些瀏覽器最多只保持 60 秒,所以可以設定為 60 秒。若將它設置為 0,就禁止了 keepalive 連接。

# 配置段: http, server, location
keepalive_timeout 60s;

client_body_timeout

指定客戶端與服務端建立連接后發(fā)送 request body 的超時時間。如果客戶端在指定時間內沒有發(fā)送任何內容,Nginx 返回 HTTP 408(Request Timed Out)。

# 配置段: http, server, location
client_body_timeout 20s;

client_header_timeout

客戶端向服務端發(fā)送一個完整的 request header 的超時時間。如果客戶端在指定時間內沒有發(fā)送一個完整的 request header,Nginx 返回 HTTP 408(Request Timed Out)。

# 配置段: http, server, location
client_header_timeout 10s;

send_timeout

服務端向客戶端傳輸數(shù)據(jù)的超時時間。

# 配置段: http, server, location
send_timeout 30s;

客戶度連接nginx超時, 建議5s內

接收客戶端header超時, 默認60s, 如果60s內沒有收到完整的http包頭, 返回408

Syntax: client_header_timeout time;
Default:  
client_header_timeout 60s;
Context:  http, server
Defines a timeout for reading client request header. If a client does not transmit the entire header within this time, 
the 408 (Request Time-out) error is returned to the client.

接收客戶端body超時, 默認60s, 如果連續(xù)的60s內沒有收到客戶端的1個字節(jié), 返回408

Syntax: client_body_timeout time;
Default:  
client_body_timeout 60s;
Context:  http, server, location
Defines a timeout for reading client request body. The timeout is set only for a period between two successive read operations, not for the transmission of the whole request body. 
If a client does not transmit anything within this time, 
the 408 (Request Time-out) error is returned to the client.

keepalive時間,默認75s,通常keepalive_timeout應該比client_body_timeout大

Syntax: keepalive_timeout timeout [header_timeout];
Default:  
keepalive_timeout 75s;
Context:  http, server, location
The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The zero value disables keep-alive client connections. 
The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field. Two parameters may differ.

The “Keep-Alive: timeout=time” header field is recognized by Mozilla and Konqueror. MSIE closes keep-alive connections by itself in about 60 seconds.

可以理解為TCP連接關閉時的SO_LINGER延時設置,默認5s

Syntax: lingering_timeout time;
Default:  
lingering_timeout 5s;
Context:  http, server, location
When lingering_close is in effect, this directive specifies the maximum waiting time for more client data to arrive. If data are not received during this time, 
the connection is closed. Otherwise, the data are read and ignored, and nginx starts waiting for more data again. 
The “wait-read-ignore” cycle is repeated, but no longer than specified by the lingering_time directive.

域名解析超時,默認30s

Syntax: resolver_timeout time;
Default:  
resolver_timeout 30s;
Context:  http, server, location
Sets a timeout for name resolution, for example:
resolver_timeout 5s;

發(fā)送數(shù)據(jù)至客戶端超時, 默認60s, 如果連續(xù)的60s內客戶端沒有收到1個字節(jié), 連接關閉

Syntax: send_timeout time;
Default:  
send_timeout 60s;
Context:  http, server, location
Sets a timeout for transmitting a response to the client. The timeout is set only between two successive write operations, 
not for the transmission of the whole response. If the client does not receive anything within this time, the connection is closed.

nginx與upstream server的連接超時時間

Syntax: proxy_connect_timeout time;
Default:  
proxy_connect_timeout 60s;
Context:  http, server, location
Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.

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

Syntax: proxy_read_timeout time;
Default:  
proxy_read_timeout 60s;
Context:  http, server, location
Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, 
not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.

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

Syntax: proxy_send_timeout time;
Default:  
proxy_send_timeout 60s;
Context:  http, server, location
Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, 
not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.

關于怎么在Nginx中配置timeout超時問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創(chuàng)新互聯(lián)成都網(wǎng)站設計公司行業(yè)資訊頻道了解更多相關知識。

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

分享文章:怎么在Nginx中配置timeout超時-創(chuàng)新互聯(lián)
文章路徑:http://muchs.cn/article12/degcgc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、App設計、網(wǎng)站策劃、外貿網(wǎng)站建設、營銷型網(wǎng)站建設、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設計