fastcgi_connect_timeout
Sets the timeout for connection attempts to a FastCGI server.
Description
The fastcgi_connect_timeout directive specifies the maximum time that NGINX will wait for a connection to a FastCGI server before failing the request. This timeout is crucial when your FastCGI server is under heavy load or is slow to respond, as it helps to prevent your NGINX server from hanging indefinitely while waiting to establish a connection. If the connection cannot be established within the specified time frame, the request will be aborted and a 504 Gateway Timeout error will be returned to the client.
This directive is set in the configuration context of http, server, or location, which allows it to be configured globally or specifically for certain server blocks or location paths. The value for fastcgi_connect_timeout is specified in seconds and can be set to a positive integer value. It is important to choose an appropriate value based on the expected response times from your FastCGI server, ensuring that it is neither too long (leading to unnecessary delays) nor too short (causing premature timeouts).
Config Example
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_connect_timeout 30s;
include fastcgi_params;
}Setting a value that is too low may lead to frequent timeouts under normal load conditions.
Ensure that other timeout settings (like fastcgi_read_timeout) do not conflict with this directive.
Configuration context limits must be adhered to; setting this directive outside of a valid context will result in an error.