TransWikia.com

nginx as Reverse Proxy - Disable Upstream Node if 502

Server Fault Asked by user2770362 on December 11, 2021

There is a very simple LB, say, LB1

upstream api_servers {
    least_conn;
        server 10.0.0.193;
        server 10.0.0.11;
    }
server {
    location / {
        proxy_http_version 1.1;
        proxy_pass http://api_servers;
    }
}

Each of the upstream servers is also an nginx LB running locally and reverse proxying a process on 9000 port. The problem is that when any of the processes on port 9000 go down, then LB1 happily returns 502 if request hits one of the machines where the process is down.

LB1:nginx:80 -> 10.0.0.193:nginx:80 -> localhost:9000

How do I tell nginx LB1 to not send requests to a node, which responds with 502?

2 Answers

Use ngx_http_proxy_module

The default is "error timeout" but you can tell him to catch 502 errors.

In your configuration this would be:

location / {
    proxy_http_version 1.1;
    proxy_pass http://api_servers;
    proxy_next_upstream error timeout http_502;
}

Answered by Federico Galli on December 11, 2021

Would be nice to know the formal answer,as to how make nginx ingore an upstream server if it fails with 502, but in this particular case it is just easier let LB1 contact servers on 9000 and remove intermediate nginx,which is there for historical reasons.

Answered by user2770362 on December 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP