$sent_http_keep_alive

The $sent_http_keep_alive variable in NGINX contains the value of the 'Keep-Alive' header sent to the client in the response. — NGINX Core (HTTP)

$sent_http_keep_alive NGINX Core (HTTP)

Description

The $sent_http_keep_alive variable is set by the NGINX core when the response is being prepared for the client. It reflects the 'Keep-Alive' header sent in the HTTP response, which informs the client whether the server wants to keep the connection open for multiple HTTP requests or close it after the current transaction. This variable can take values such as 'timeout=5', which indicates how long the connection should be kept alive before timing out, or 'timeout=0' indicating that the connection should be closed immediately after the response is sent. When configured with keep-alive settings, NGINX manages persistent connections efficiently and uses this variable to communicate the server's preferences back to the client. If keep-alive is disabled or not applicable, this variable may be left blank. The state of $sent_http_keep_alive can also be influenced by various directives such as 'keepalive_timeout', which determines how long the server will allow a connection to remain idle before it is closed, making this variable critical for performance in high-traffic environments where maintaining open connections can reduce latency for subsequent requests from the same client.

Config Example

http {
    keepalive_timeout 65;
    server {
        listen 80;
        location / {
            add_header Keep-Alive "$sent_http_keep_alive";
        }
    }
}

Subsystem

http

Cacheable

Yes

Contexts

http, server, location

The variable will be empty if keep-alive is not set or disabled; make sure to enable keep-alive in your configuration.

If the Keep-Alive header is not included in the response for specific requests, the variable will not have any value.