6

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?

2 Answers 2

2

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 as backup? Documentation is not specific of what behaviour is to be expected in a situation like this; I would argue that specifying two backup servers should make nginx 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.

1

Sure you can just create a separate "server config" for your app-server-XX on some other ports in the same nginx.conf and configure it as you want. Then you can use it in your "mybackend" upstream exactly as you told before.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .