当前位置: > Linux服务器 > nginx >

Nginx的各种timeout

时间:2019-06-04 15:49来源:linux.it.net.cn 作者:IT

1. keepalive_timeout(context:httpserverlocation)

Syntax: keepalive_timeout timeout [header_timeout];
Default:
keepalive_timeout 75s;
Context: httpserverlocation

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.

第一个参数设置一个超时,在此期间保持活动的客户端连接将在服务器端保持打开状态。 0值禁用保持活动的客户端连接。 可选的第二个参数表示设置值在“Keep-Alive:timeout = time”响应头字段中,两个参数可能不同。

Mozilla和Konqueror识别“Keep-Alive:timeout = time”标题字段。 MSIE在大约60秒内自行关闭保持连接。

 

HTTP 是一种无状态协议,客户端向服务器发送一个 TCP 请求,服务端响应完毕后断开连接。

如果客户端向服务器发送多个请求,每个请求都要建立各自独立的连接以传输数据。

HTTP的KeepAlive模式告诉Nginx在处理完一个请求后保持这个 TCP 连接的打开状态。若接收到来自同一客户端的其它请求,服务端会利用这个未被关闭的连接,而不需要再建立一个连接。

KeepAlive 在一段时间内保持打开状态,它们会在这段时间内占用资源。占用过多就会影响性能。

Nginx 使用 keepalive_timeout 来指定 KeepAlive 的超时时间。指定每个 TCP 连接最多可以保持多长时间。Nginx 的默认值是 75 秒,有些浏览器最多只保持 60 秒,所以可以设定为 60 秒。

 

2. keepalive_timeout(context: upstream

Syntax: keepalive_timeout timeout;
Default:
keepalive_timeout 60s;
Context: upstream

This directive appeared in version 1.15.3. Sets a timeout during which an idle keepalive connection to an upstream server will stay open.

该指令出现在1.15.3版中。设置超时时间,在此期间与上游服务器的空闲keepalive连接将保持打开状态。

 

3. client_header_timeout

Syntax: client_header_timeout time;
Default:
client_header_timeout 60s;
Context: httpserver

Defines a timeout for reading client request header. If a client does not transmit the entire header within this time, the request is terminated with the 408 (Request Time-out) error.

定义读取客户端请求头的超时。 如果客户端在此时间内未传输整个标头,请求将以408(请求超时)错误终止。

 

4. client_body_timeout

Syntax: client_body_timeout time;
Default:
client_body_timeout 60s;
Context: httpserverlocation

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 request is terminated with the 408 (Request Time-out) error.

定义读取客户端请求正文的超时。 超时仅设置为两个连续读取操作之间的时间段,而不是整个请求主体的传输。 如果客户端在此时间内未传输任何内容,请求将以408(请求超时)错误终止。

5. send_timeout

Syntax: send_timeout time;
Default:
send_timeout 60s;
Context: httpserverlocation

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.

设置将响应传输到客户端的超时。 仅在两个连续的写操作之间设置超时,而不是为整个响应的传输。 如果客户端在此时间内未收到任何内容,则会关闭连接。

 

6. fastcgi_connect_timeout

 

Syntax: fastcgi_connect_timeout time;
Default:
fastcgi_connect_timeout 60s;
Context: httpserverlocation

Defines a timeout for establishing a connection with a FastCGI server. It should be noted that this timeout cannot usually exceed 75 seconds.

定义与FastCGI服务器建立连接的超时。 应该注意,此超时通常不会超过75秒。

 

7. fastcgi_send_timeout

Syntax: fastcgi_send_timeout time;
Default:
fastcgi_send_timeout 60s;
Context: httpserverlocation

Sets a timeout for transmitting a request to the FastCGI server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the FastCGI server does not receive anything within this time, the connection is closed.

设置将请求传输到FastCGI服务器的超时。 仅在两次连续写入操作之间设置超时,而不是为整个请求的传输。 如果FastCGI服务器在此时间内未收到任何内容,则关闭连接。

 

8. fastcgi_read_timeout

 

Syntax:

fastcgi_read_timeout time;
Default:
fastcgi_read_timeout 60s;
Context: httpserverlocation

Defines a timeout for reading a response from the FastCGI server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the FastCGI server does not transmit anything within this time, the connection is closed. 

定义从FastCGI服务器读取响应的超时。 仅在两个连续的读操作之间设置超时,而不是为整个响应的传输。 如果FastCGI服务器在此时间内未传输任何内容,则关闭连接。

 

9. proxy_connect_timeout

Syntax: proxy_connect_timeout time;
Default:
proxy_connect_timeout 60s;
Context: httpserverlocation

Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.

定义与代理服务器建立连接的超时。 应该注意,此超时通常不会超过75秒。

 

10. proxy_send_timeout

Syntax: proxy_send_timeout time;
Default:
proxy_send_timeout 60s;
Context:

httpserverlocation

 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.

设置将请求传输到代理服务器的超时。 仅在两次连续写入操作之间设置超时,而不是为整个请求的传输。 如果代理服务器在此时间内未收到任何内容,则关闭连接。

11. proxy_read_timeout

Syntax: proxy_read_timeout time;
Default:
proxy_read_timeout 60s;
Context: httpserverlocation

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.

 定义从代理服务器读取响应的超时。 仅在两个连续的读操作之间设置超时,而不是为整个响应的传输。 如果代理服务器在此时间内未传输任何内容,则关闭连接。

 

 

 

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容