proxy_socket_keepalive

The `proxy_socket_keepalive` directive enables or disables the use of keepalive for the connections to proxied servers. — NGINX HTTP Core

proxy_socket_keepalive
httpserverlocation
Синтаксисproxy_socket_keepalive on | off;
По умолчаниюoff
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументыflag

Описание

The `proxy_socket_keepalive` directive controls whether keepalive should be activated for connections to proxied servers within NGINX. When set to `on`, NGINX maintains persistent connections to upstream servers for reuse, which can significantly reduce the latency associated with establishing new connections for subsequent requests from clients. This is particularly beneficial for environments experiencing high traffic to upstream servers, as it can help to decrease resource usage and improve response times. The directive is specified in the context of `http`, `server`, or `location`, allowing for flexible configuration based on the desired scope of keepalive connections. By default, the directive is turned `off`, meaning that NGINX will not utilize keepalive connections unless explicitly enabled. Enabling keepalive can also interoperate with other directives such as `proxy_pass`, providing seamless integration without requiring extensive configuration changes. When using `proxy_socket_keepalive`, it is essential to consider the settings from the upstream server side as well, since if the upstream does not support keepalive connections or has a shorter timeout than NGINX, it may not yield the desired performance improvements.

Пример конфига

http {
    server {
        location / {
            proxy_pass http://backend;
            proxy_socket_keepalive on;
        }
    }
}

Ensure that the upstream server is configured to support keepalive connections.

Excessive setting of keepalive can lead to resource exhaustion on the server side if not handled correctly.