0

I'm running nginx as reverse proxy on 3 different hosts. The DNS resolves production.example.com to all 3 hosts' IP addresses. Thus I have some sort of load balancing and fallback if one host is not available.

Every host is running several docker containers. Some of them are running on all three hosts, some only on two or even just one host.

Utilizing nginx's proxy_pass I forward all requests to the container's internal name (I'm using Rancher thus every container is accessable via container_name.stack_name via internal DNS).

Every now and then, a container is not available or does not respond and thus nginx returns an error 502.

Is there any way to have and automatic fallback for this? Unfortunately nginx ignores all other resolved addresses for an internal Docker container name and thus does not forward the request to a different address.

1

You should use the proxy_next_upstream directive

Specifies in which cases a request should be passed to the next server

location / {
    proxy_pass http://backends;
    proxy_next_upstream error timeout http_502;
}
1
  • In my case, I don't know the "backends". They're dynamically specified via DNS. In other words, I don't use the upstream directive right now and even If I would use it, it would only specifiy a single server in it.
    – Sn0opy
    Oct 24 '17 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.