this is my current upstream definition
upstream mybackend {
server cache-server;
server app-server-1 backup;
server app-server-2 backup;
}
Every request goes to cache-server and when it's down the requests will go to app-server-1 without balancing between app-server-1 and -2.
Is it possible to do something like this?
upstream mybackend {
server cache-server;
server app-server-cluster backup;
}
upstream app-server-cluster{
server app-server-1;
server app-server-2;
}
… when cache-server goes down nginx will take the app-server-cluster and will balance between 1 and 2?
Best Answer
No, nesting in such a way is not currently supported. The documentation at http://nginx.org/docs/http/ngx_http_upstream_module.html#server is pretty clear in what kind of parameters the
server
directive accepts.On the other hand, are you certain that in the existing configuration
nginx
would not be balancing the load between appserver-1 and -2, if you specify both asbackup
? Documentation is not specific of what behaviour is to be expected in a situation like this; I would argue that specifying twobackup
servers should makenginx
balance the requests between all such backup servers; if that's not the case, but you need it to be, then perhaps you should log an RfE: http://nginx.org/en/support.html.