scgi_socket_keepalive

The 'scgi_socket_keepalive' directive enables or disables keep-alive support for SCGI connections.

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

Description

The 'scgi_socket_keepalive' directive is used in the NGINX HTTP core module to manage keep-alive connections for SCGI (Simple Common Gateway Interface) protocols. By setting this directive to 'on', it allows the SCGI socket to maintain an open connection with the client, enabling reuse of the same socket for multiple requests. This can enhance performance by reducing connection overhead, especially for applications that frequently interact with SCGI backend servers. Conversely, if set to 'off', each request will establish a new connection, which may increase latency due to the overhead of connection establishment and teardown.

The directive can be placed in 'http', 'server', or 'location' contexts, allowing for flexible configurations depending on the needs of the application. A common use case is within locations that serve dynamic content generated by SCGI applications, where keeping the connection alive may improve throughput and reduce resource consumption in high-traffic scenarios. Importantly, it is compatible with all SCGI commands.

Keep-alive settings can significantly impact the behavior of backend communication. Therefore, it is advisable to monitor the application’s traffic patterns and performance metrics when enabling this feature, as it can lead to increased resource utilization if many connections are kept alive simultaneously.

Config Example

location /app {
    scgi_pass 127.0.0.1:4000;
    scgi_socket_keepalive on;
}

Ensure that the backend SCGI server supports keep-alive connections.

Using keep-alive without appropriate load balancing strategies may lead to resource starvation.

Beware of increased memory usage if too many connections are kept alive for too long.

← Back to all directives