nginx nested upstream

Solution 1:

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.

Solution 2:

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.