What are the Nginx network connection configuration items?

coldplay.xixi
Release: 2020-06-29 16:55:10
Original
3147 people have browsed it

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 .

What are the Nginx network connection configuration items?

Nginx network connection configuration items are:

1. Timeout for reading HTTP headers

Syntax:

client_header_timeout time(默认单位:秒);
Copy after login

Default:

client_header_timeout 60;
Copy after login

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(默认单位:秒);
Copy after login

Default:

client_body_timeout 60;
Copy after login

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;
Copy after login

Default:

send_timeout 60;
Copy after login

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;
Copy after login

Default:

reset_timeout_connection off;
Copy after login

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;
Copy after login

Default:

lingering_close on;
Copy after login

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;
Copy after login

Default:

lingering_time 30s;
Copy after login

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;
Copy after login

Default:

lingering_timeout 5s;
Copy after login

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 ]...
Copy after login

Default:

keepalive_disable  msie6 safari
Copy after login

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, keepaliveTimeout time

Syntax:

keepalive_timeout time(默认单位:秒);
Copy after login

Default:

keepalive_timeout 75;
Copy after login

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;
Copy after login

Default:

keepalive_requests 100;
Copy after login

配置块:http、server、location

一个keepalive连接上默认最多只能发送100个请求。

11、 tcp_nodelay

语法:

tcp_nodelay on | off;
Copy after login

默认:

tcp_nodelay on;
Copy after login

配置块: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;
Copy after login

默认:

tcp_nopush off;
Copy after login

配置块: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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template