Nginx network connection configuration items are: 1. Timeout for reading HTTP headers; 2. Timeout for reading HTTP packet bodies; 3. Timeout for sending responses; 4. Reset timeout connection options .
Nginx network connection configuration items are:
1. Timeout for reading HTTP headers
Syntax:
client_header_timeout time(默认单位:秒);
Default:
client_header_timeout 60;
Configuration block: http, server, location
Will start after the client establishes a connection with the server Receive HTTP headers. During this process, if no bytes from the client are read within a time interval (timeout time), it will be considered a timeout and a 408 ("Request timed out") response will be returned to the client. .
Recommended tutorial: nginx quick start tutorial
2. Timeout for reading HTTP packet body
Syntax:
client_body_timeout time(默认单位:秒);
Default:
client_body_timeout 60;
Configuration block: http, server, location
This configuration item is similar to client_header_timeout, except that this timeout is only for reading Valid only in HTTP packet body.
3. Timeout for sending response
Syntax:
send_timeout time;
Default:
send_timeout 60;
Configuration block: http, server, location
This timeout is the timeout for sending a response, that is, the Nginx server sent a data packet to the client, but the client never received the data packet. If a connection exceeds the timeout defined by send_timeout, Nginx will close the connection.
4. Reset timeout connection option
Syntax:
reset_timeout_connection on | off;
Default:
reset_timeout_connection off;
Configuration block: http, server, location
After the connection times out, the connection will be reset directly by sending an RST packet to the client. After this option is turned on, Nginx will not use the normal four-way handshake to close the TCP connection after a certain connection times out. Instead, it will directly send an RST reset packet to the user, no longer wait for the user's response, and directly release the Nginx server. Regarding all caches used by this socket (such as TCP sliding windows). Compared with the normal shutdown method, it allows the server to avoid generating many TCP connections in the FIN_WAIT_1, FIN_WAIT_2, and TIME_WAIT states.
Note that using the RST reset package to close the connection will cause some problems and will not be enabled by default.
5, lingering_close
Syntax:
lingering_close off | on | always;
Default:
lingering_close on;
Configuration block: http, server, location
This configuration controls how Nginx closes user connections. always means that data sent by all users on the connection must be processed unconditionally before closing the user connection. off means that when closing the connection, it does not care whether there is ready data from the user on the connection. on is an intermediate value. Under normal circumstances, the data sent by users on the connection will be processed before closing the connection, except in some cases where the business determines that the data after this is unnecessary.
6, lingering_time
Syntax:
lingering_time time;
Default:
lingering_time 30s;
Configuration block: http, server, location
When lingering_close is enabled, this configuration item is useful for uploading large files. As mentioned above, when the Content-Length requested by the user is greater than the max_client_body_size configuration, the Nginx service will immediately send a 413 (Request entity too large) response to the user. However, many clients may continue to upload the HTTP body regardless of the 413 return value. At this time, after the lingering_time setting has passed, Nginx will close the connection regardless of whether the user is still uploading.
7, lingering_timeout
Syntax:
lingering_timeout time;
Default:
lingering_timeout 5s;
Configuration block: http, server, location
After lingering_close takes effect, before closing the connection, it will detect whether any data sent by the user reaches the server. If there is no data to read after lingering_timeout, the connection will be closed directly; otherwise, it must be read before The connection will not be closed until the data in the connection buffer is fetched and discarded.
8. Disable the keepalive function for some browsers
Syntax:
keepalive_disable [ msie6 | safari | none ]...
Default:
keepalive_disable msie6 safari
Configuration block: http, server, location
The keepalive function in HTTP requests is to reuse a long HTTP connection for multiple requests. This function is very helpful for improving the performance of the server. But some browsers, such as IE 6 and Safari, have functional problems with POST request processing using the keepalive function. Therefore, for IE 6 and its earlier versions, the keepalive function is disabled by default in Safari browser.
8, keepalive
Timeout time
Syntax:
keepalive_timeout time(默认单位:秒);
Default:
keepalive_timeout 75;
Configuration block: http, server , location
After a keepalive connection has been idle for a certain period of time (the default is 75 seconds), both the server and the browser will close the connection. Of course, the keepalive_timeout configuration item is used to constrain the Nginx server. Nginx will also pass this time to the browser according to the specifications, but each browser may have different strategies for treating keepalives.
10. The maximum number of requests allowed to be carried on a keepalive
long connection
Syntax:
keepalive_requests n;
Default:
keepalive_requests 100;
配置块:http、server、location
一个keepalive连接上默认最多只能发送100个请求。
11、 tcp_nodelay
语法:
tcp_nodelay on | off;
默认:
tcp_nodelay on;
配置块:http、server、location
确定对keepalive连接是否使用TCP_NODELAY选项。
<span style="font-family:Microsoft Yahei, Hiragino Sans GB, Helvetica, Helvetica Neue, 微软雅黑, Tahoma, Arial, sans-serif">12、</span>tcp_nopush
语法:
tcp_nopush on | off;
默认:
tcp_nopush off;
配置块:http、server、location
在打开sendfile选项时,确定是否开启FreeBSD系统上的TCP_NOPUSH
或Linux系统上的TCP_CORK功能。打开tcp_nopush后,将会在发送响应时把整个响应包头放到一个TCP包中发送。
The above is the detailed content of What are the Nginx network connection configuration items?. For more information, please follow other related articles on the PHP Chinese website!