scgi_next_upstream_tries
The 'scgi_next_upstream_tries' directive specifies the number of attempts to connect to the next upstream server in case of a failure in SCGI service communication.
Description
The 'scgi_next_upstream_tries' directive configures how many attempts NGINX will make to communicate with another SCGI upstream server when the initial upstream server fails to respond appropriately. It is particularly useful in situations where you have multiple SCGI servers defined in your NGINX configuration, allowing for fault tolerance and improved server reliability. This directive can take a single integer argument which represents the total number of retries that should be made before giving up on connecting to further upstream servers.
When set, if an SCGI request fails due to network issues, a timeout, or any other error recognized during the processing of the request, NGINX will attempt to forward the request to the next upstream server as specified in the SCGI block. This behavior can help to distribute load and improve application availability. If all specified attempts are exhausted without a successful connection, NGINX will return an error response to the client.
It is important to configure this directive carefully according to the specifics of your application and server capabilities to avoid unnecessary delays in request handling, especially under conditions of high traffic or when upstream servers may not be immediately available.
Config Example
http {
upstream backend {
server backend1.example.com;
server backend2.example.com;
}
location /scgi {
include fastcgi_params;
scgi_pass backend;
scgi_next_upstream_tries 3;
}
}Setting a very high number can cause long delays in response times if upstream servers are failing consistently.
Ensure that 'scgi_pass' is properly configured; otherwise, the directive may not take effect as expected.