The timeout timeout time setting in the nginx configuration file (detailed)

The timeout timeout time setting in the nginx configuration file (detailed)

nginx basic timeout configuration

  You can refer to the module on the official website ngx_http_core_module, the document address: http://nginx.org/en/docs/http/ngx_http_core_module.html

client_header_timeout

Syntax(语法):	client_body_timeout time;
Default(默认值): client_body_timeout 60s;
Context(上下文):	http, server, location

Description: Specifies the timeout period to wait for the client to send a request header. If the client does not send anything within the timeout period, nginx returns HTTP status code 408 ("Request timed out")

client_body_timeout

Syntax(语法):	client_body_timeout time;
Default(默认值): client_body_timeout 60s;
Context(上下文): http, server, location

Description: This command sets the read timeout period for the request body (request body). The timeout is only set to the period between two consecutive read operations, not the transfer of the entire request body.如果客户端在此时间内未传输任何内容,请求将以408(请求超时)错误终止。

keepalive_timeout (long connection type)

Syntax(语法):	keepalive_timeout timeout [header_timeout];
Default(默认值): keepalive_timeout 75s;
Context(上下文): http, server, location

Description: The first parameter sets a timeout during which keep-alive client connections will remain open on the server side. 0 disables the client's keep-aliveconnection. The optional second parameter sets a value in the "Keep-Alive: timeout=time" response header field. The two parameters may be different. 第二个参数,用于给浏览器进行判断是否需要关闭keepavlie连接的,如果客户端(浏览器)在header_timeout 之后如果没有任何数据传输,就会主动关闭连接。Mozilla and Konqueror recognize the "Keep-Alive: timeout=time" header field. MSIE closes keepalives on its own in about 60 seconds.

resolver_timeout

Syntax(语法):	resolver_timeout time;
Default(默认值): resolver_timeout 30s;
Context(上下文): http, server, location

Description: It is mainly specified DNS解析的超时时间. This is resolver address ... [valid=time] [ipv6=on|off];related to the configuration. The resolver configuration can specify the DNS server, and this timeout is used for the DNS server configured here.

send_timeout

Syntax(语法):	send_timeout time;
Default(默认值): send_timeout 60s;
Context(上下文): http, server, location

Description: Sets the timeout for transmitting the response to the client. only in 两个连续的写操作之间设置超时,而不是为整个响应的传输. If the client does not receive anything within this time, the connection is closed. This is the timeout period for Nginx to send data to the client (browser).

lingering_timeout

Syntax(语法):	lingering_timeout time;
Default(默认值): lingering_timeout 5s;
Context(上下文): http, server, location

Description: When lingering_close is in effect, this directive specifies the maximum wait time for more client data to arrive. If no data is received during this time, the connection is closed. Otherwise, the data is read and ignored, and nginx starts waiting for more data again. Repeat the "wait-read-ignore" loop, but no more than the loop specified by the lingering_time directive. (not quite understanding...)

Proxy related timeout configuration

  You can refer to the module on the official website ngx_http_proxy_module, the document address: http://nginx.org/en/docs/http/ngx_http_proxy_module.html

proxy_connect_timeout

Syntax(语法):	proxy_connect_timeout time;
Default(默认值): proxy_connect_timeout 60s;
Context(上下文): http, server, location

Description: This command sets the connection timeout time with the upstream server. It is necessary to remember this timeout 不能超过75秒. At this time, Nginx tries to establish a connection with the upstream server. If the connection is not established successfully within 60s, the connection will be abandoned.

proxy_read_timeout

Syntax(语法):	proxy_read_timeout time;
Default(默认值): proxy_read_timeout 60s;
Context(上下文): http, server, location

Description: Defines the timeout for reading responses from the proxy server. Set the timeout only between two consecutive read operations, not for the transfer of the entire response. If the proxy server does not transmit anything within this time, the connection is closed.这个时间是用于读取上游服务器响应时,最长的读取等待时间,如果超过这个时间,Nginx会主动关闭连接。

proxy_send_timeout

Syntax(语法):	proxy_send_timeout time;
Default(默认值): proxy_send_timeout 60s;
Context(上下文): http, server, location

Description: Sets the timeout for transmitting requests to the proxy server. Set the timeout only between two consecutive write operations, not for the entire requested transfer. If the proxy server does not receive anything within this time, the connection is closed.这个是Nginx向上游服务器传输数据时的超时时间,如果发现写入时超过了这个时间都没有成功则Nginx会关闭这个链接。

Summarize

  For Nginx's timeout configuration, the default configuration is generally enough, but sometimes some errors are related to these timeouts, and different configurations will have different effects. The main reference here is to refer to the official documents, plus some of your own understanding. If there is any error, please point it out and learn together.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324113972&siteId=291194637