proxy_half_close

The `proxy_half_close` directive controls whether NGINX closes the upstream connection after the client connection is closed in stream module configurations.

Syntaxproxy_half_close on | off;
Defaultoff
Contextstream, stream server
Argumentsflag

Description

The proxy_half_close directive is utilized within the NGINX Stream module context, specifically in stream and stream server configurations. When enabled (set to 'on'), it allows the server to close the upstream connection once the client has finished sending data and closed their connection. This is particularly useful for certain protocols where the upstream server may need to continue processing data after the client disconnects, ensuring resource efficiency and proper handling of transient connections.

In the absence of this directive, by default (when set to 'off'), NGINX maintains the upstream connection even after the client closes. This behavior could lead to unnecessary resource consumption because the upstream server remains open longer than needed. The proxy_half_close directive can be particularly important in scenarios where the downstream connections are frequent and short-lived, or when it is essential to manage socket states efficiently to optimize performance.

The directive accepts a single argument: on or off. Setting it to 'on' enables the half-close behavior, while 'off' (the default setting) means that NGINX will not close the upstream connection immediately after the client-side disconnect. This setting allows flexibility in managing connection lifecycles based on the specific needs of your application and the types of protocols you are implementing.

Config Example

stream {
    server {
        listen 12345;
        proxy_pass backend_servers;
        proxy_half_close on;
    }
}

Make sure to test connection behavior carefully; enabling this might introduce changes in how data flows between client and upstream servers.

If using with protocols that expect session persistence, verify that half-closing does not lead to unexpected disconnections.

← Back to all directives