fastcgi_read_timeout

The `fastcgi_read_timeout` directive sets the maximum time NGINX will wait for a response from a FastCGI server before timing out.

Syntaxfastcgi_read_timeout time;
Default60s
Contexthttp, server, location
Arguments1

Description

The fastcgi_read_timeout directive is used to specify the duration that NGINX will wait for a response from a FastCGI server after sending a request. This is useful for scenarios where the FastCGI processing might take longer than expected, and you want to avoid prematurely closing connections that might still respond eventually. The timeout applies individually to each request and can be specified in various contexts such as http, server, and location blocks.

The parameter for this directive is a time value, which can be specified in seconds (s), minutes (m), hours (h), or days (d). If the timeout duration is exceeded and no response is received, NGINX will terminate the connection to the FastCGI server and can return an error to the client. Adjusting the fastcgi_read_timeout can be crucial for optimizing performance in applications that might require longer processing times, like those performing complex database queries or file operations.

It is important to note that setting this value too low may lead to unwanted connection closures, while setting it too high may cause clients to wait unnecessarily long for responses that will never arrive. Therefore, balancing this value based on the application's performance characteristics is recommended.

Config Example

location /api {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_read_timeout 120s;
}

Setting a very low timeout may cause legitimate requests to fail if they take longer to process.

If you set a timeout higher than the PHP maximum execution time, the timeout will still apply as per this directive; hence, your application may need to align those settings.

← Back to all directives