1. 程式人生 > 其它 >超時時間proxy_read_timeout和fastcgi_read_timeout 詳解

超時時間proxy_read_timeout和fastcgi_read_timeout 詳解

使用nginx伺服器如果遇到timeou情況時可以如下設定引數,使用fastcgi:

fastcgi_connect_timeout 75; 連結

fastcgi_read_timeout 600; 讀取

fastcgi_send_timeout 600; 發請求

這兩個選項.
fastcgi_read_timeout是指fastcgi程序向nginx程序傳送response的整個過程的超時時間
fastcgi_send_timeout是指nginx程序向fastcgi程序傳送request的整個過程的超時時間

這兩個選項預設都是秒(s),可以手動指定為分鐘(m),小時(h)等

keepalive_timeout

HTTP 是一種無狀態協議,客戶端向伺服器傳送一個 TCP 請求,服務端響應完畢後斷開連線。

如果客戶端向伺服器傳送多個請求,每個請求都要建立各自獨立的連線以傳輸資料。

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

KeepAlive 在一段時間內保持開啟狀態,它們會在這段時間內佔用資源。佔用過多就會影響效能。

Nginx 使用 keepalive_timeout 來指定 KeepAlive 的超時時間(timeout)。指定每個 TCP 連線最多可以保持多長時間。Nginx 的預設值是 75 秒,有些瀏覽器最多隻保持 60 秒,所以可以設定為 60 秒。若將它設定為 0,就禁止了 keepalive 連線。通常 keepalive_timeout 應該比 client_body_timeout(見下文)大.

# 配置段: http, server, location

keepalive_timeout 60s;

client_body_timeout

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

# 配置段: http, server, location

client_body_timeout 20s;

client_header_timeout

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

# 配置段: http, server, location

client_header_timeout 10s;

send_timeout

服務端向客戶端傳輸資料的超時時間,根據轉發的應用服務可以配置 proxy_send_timeout、uwsgi_send_timeout、fastcgi_send_timeout(見下文)。

# 配置段:http, server, location

send_timeout 30s;
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.

client_header_timeout

接收客戶端 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.

client_body_timeout

接收客戶端 body 超時, 預設 60s, 如果連續的 60s 內沒有收到客戶端的 1 個位元組, 返回 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.

lingering_timeout

可以理解為 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.

resolver_timeout

域名解析超時,預設 30s

Syntax: resolver_timeout time;

Default:

resolver_timeout 30s;

Context: http, server, location

Sets a timeout for name resolution, for example:

resolver_timeout 5s;

proxy_connect_timeout

nginx 與 upstream server 的連線超時時間,預設為 60s;根據應用不同可配置 uwsgi_send_timeout/fascgi_send_timeout/proxy_send_timeout

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.

proxy_read_timeout

nginx 接收 upstream server 資料超時, 預設 60s, 如果連續的 60s 內沒有收到 1 個位元組, 連線關閉;根據應用不同可配置 uwsgi_send_timeout/fascgi_send_timeout/proxy_send_timeout

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.

proxy_send_timeout

nginx 傳送資料至 upstream server 超時, 預設 60s, 如果連續的 60s 內沒有傳送 1 個位元組, 連線關閉;根據應用不同可配置 uwsgi_send_timeout/fascgi_send_timeout/proxy_send_timeout。

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 rec


參考:https://ld246.com/article/1543809580828

https://blog.csdn.net/mnasd/article/details/80253628