lingering_close
The `lingering_close` directive enables or disables lingering close for HTTP connections in NGINX.
Description
The lingering_close directive in NGINX controls the behavior of lingering closes for client connections. When set to 'on', it allows connections to remain open for a specified period after the client has sent a request, providing a chance for the client to read remaining data before the connection is fully closed. This is particularly useful for handling slow clients or those which may not read all data promptly, thus preventing potential data loss. When set to 'off', NGINX will close the connection immediately after sending the response without waiting for the client, which can improve server performance in high-traffic scenarios but at the risk of losing unconsumed data.
The directive takes a single argument, which can be either 'on' or 'off'. In its 'on' state, NGINX will perform a lingering close where it allows the connection to stay open. If the directive is set to 'off', the lingering close feature is disabled, and the connections are closed right away. This directive can be used in various contexts, including http, server, and location, making it flexible for different application needs. When fine-tuning performance, NGINX administrators can leverage this directive to optimize data handling based on their specific use cases and client behaviors.
Config Example
server {
listen 80;
server_name example.com;
lingering_close on;
}Setting lingering_close to 'on' may lead to resource exhaustion if there are too many slow clients.
Disabling lingering_close can result in data loss if clients do not consume the entire response.