fastcgi_next_upstream_tries
The `fastcgi_next_upstream_tries` directive controls the number of times NGINX will retry the next upstream server when a FastCGI request fails.
Description
The fastcgi_next_upstream_tries directive specifies how many upstream servers should be tried in case of an unsuccessful FastCGI request. By setting this directive, NGINX allows for load balancing across backend FastCGI servers by attempting to retry the request on a specified number of other servers if the initial server fails. This can be particularly useful in scenarios where high availability is critical, and you want to ensure your application continues to function even if one or more upstream servers are down.
When specifying the value of this directive, you can define it in the http, server, or location context, which allows for fine-tuning based on different application needs. For example, you could set a higher value in a location that is more susceptible to failures, while keeping a lower value in more stable areas of your application. The value specified must be a positive integer, and if set to zero, it effectively disables the feature, meaning NGINX will not attempt to retry on other upstream servers.
It's worth noting that the directive interacts with other FastCGI related directives, particularly fastcgi_next_upstream which determines under what conditions the retries will occur. Combining the two allows for comprehensive control over how NGINX handles backend failures and failover.
Config Example
location /api {
fastcgi_pass backend;
fastcgi_next_upstream_tries 3;
}Setting the value to zero disables the retry mechanism entirely, which may lead to more frequent errors if the initial FastCGI server is down.
Ensure that the FastCGI servers are capable of handling retries; otherwise, the same failure may occur on the next attempt.