Question

I'm trying to determine if it is possible to tell Nginx to choose another server for a specified upstream when the first server selected returns a specific error.

Eg:

try upstream server 0

if it returns a certain error code (eg: 503)
    try upstream 1
else
    return response to client
Was it helpful?

Solution

Here's a sample of what you need to do, you can read more details on this answer

upstream myservers{
  #the first server is the main server
  server xxx.xxx.xxx.xxx weight=999 fail_timeout=5s max_fails=1;
  server xxx.xxx.xxx.xxx;
}

server {
    # all config
    proxy_pass http://myservers;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top