# Use next Balanced member if 503 error

**URL:** <https://www.ruby-forum.com/t/use-next-balanced-member-if-503-error/225001>\
**Category:** NGINX\
**Created:** [December 6, 2012, 6:34pm UTC](https://www.ruby-forum.com/t/use-next-balanced-member-if-503-error/225001 "2012-12-06T18:34:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [December 6, 2012, 6:34pm UTC](https://www.ruby-forum.com/t/use-next-balanced-member-if-503-error/225001/1 "2012-12-06T18:34:35Z")

</div>

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:

> **[Use next Balanced member if 503 error](https://forum.nginx.org/read.php?2,233653,233653#msg-233653)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![marcosluna79](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@marcosluna79](https://www.ruby-forum.com/u/marcosluna79)\
**Post date:** [December 7, 2012, 8:06pm UTC](https://www.ruby-forum.com/t/use-next-balanced-member-if-503-error/225001/2 "2012-12-07T20:06:41Z")

</div>

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:

> **[Module ngx\_http\_upstream\_module](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#variables)**
>
> The ngx\_http\_upstream\_module module is used to define groups of servers that can be referenced by the proxy\_pass, fastcgi\_pass, uwsgi\_pass, scgi\_pass, memcached\_pass, and grpc\_pass directives.

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/](http://127.0.0.1:8080/)  
OK  
$ curl [http://127.0.0.1:8080/](http://127.0.0.1:8080/)  
OK  
$ curl [http://127.0.0.1:8080/](http://127.0.0.1:8080/)  
OK  
$ curl [http://127.0.0.1:8080/](http://127.0.0.1:8080/)  
OK

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.
