Use next Balanced member if 503 error

Hello I am working with nginx as balancer between two jetty servers.

The balancing is working but I am facing a problem when a 503 error is
generated by one of the servers, I added the line

proxy_next_upstream error timeout invalid_header http_500 http_503;

It seems not to work when one of the servers fail because a resource is
lost
like a DB connection. I can see the 503 error page instead of the
correct
page in the other balanced member.

I have checked that the other server do have a valid DB connection but
nginx
fails to forward to it.

Thanks for your help.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,233653,233653#msg-233653

Hello!

On Thu, Dec 06, 2012 at 12:34:18PM -0500, marcosluna79 wrote:

I have checked that the other server do have a valid DB connection but nginx
fails to forward to it.

The 503 error may be returned even with “proxy_next_upstream
http_503” configured e.g. if both backends return 503 or one of the
backends was already considered down for some reason (due to
previous errors).

If you want to investigate what goes on in your case, you probably
want to log details on upstream communication like $upstream_addr,
$upstream_status, see here for more details:

http://nginx.org/en/docs/http/ngx_http_upstream_module.html#variables

Just in case, trivial config to test that “proxy_next_upstream
http_503” actually works:

http {
    upstream backends {
        server 127.0.0.1:8081;
        server 127.0.0.1:8082;
    }

    server {
        listen 8080;

        location / {
            proxy_pass http://backends;
            proxy_next_upstream error timeout http_503;
        }
    }

    server {
        listen 8081;
        return 503;
    }

    server {
        listen 8082;
        return 200 "OK\n";
    }
}

And trivial test with curl:

$ curl http://127.0.0.1:8080/
OK
$ curl http://127.0.0.1:8080/
OK
$ curl http://127.0.0.1:8080/
OK
$ curl http://127.0.0.1:8080/
OK


Maxim D.
http://nginx.com/support.html