fastcgi_socket_keepalive

The `fastcgi_socket_keepalive` directive enables or disables the keepalive feature for FastCGI socket connections.

Syntaxfastcgi_socket_keepalive on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The fastcgi_socket_keepalive directive can be used to control whether persistent connections to FastCGI servers should be kept alive. When set to 'on', NGINX will keep the FastCGI socket open after the request has been processed, allowing for additional requests to reuse the existing connection instead of establishing new ones. This can result in performance improvements by reducing the overhead of socket creation and destruction, especially under high load conditions where numerous requests are made to the same FastCGI server.

The directive can be specified within the http, server, or location contexts, making it very flexible as it can apply globally or to specific server blocks or locations. The flag can also be set to 'off' if you wish to disable keepalive behavior, so each request to the FastCGI server will establish a new connection. Adjusting this setting requires careful consideration of the FastCGI server's ability to handle persistent connections as well as any timeout configurations that might affect performance.

Config Example

http {
    server {
        location / {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_socket_keepalive on;
        }
    }
}

Enabling keepalive can lead to unexpected behavior if the FastCGI server does not properly support it, so testing is recommended.

Excessive keepalive connections can lead to resource exhaustion on the FastCGI server if not managed properly.

← Back to all directives