# Next upstream based on custom http code

**URL:** <https://www.ruby-forum.com/t/next-upstream-based-on-custom-http-code/243611>\
**Category:** NGINX\
**Created:** [December 10, 2015, 5:34pm UTC](https://www.ruby-forum.com/t/next-upstream-based-on-custom-http-code/243611 "2015-12-10T17:34:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 10, 2015, 5:34pm UTC](https://www.ruby-forum.com/t/next-upstream-based-on-custom-http-code/243611/1 "2015-12-10T17:34:57Z")

</div>

Hi

There are a few options for when to try next upstream :  
[http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html#proxy\_next\_upstream](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream)

Is it possible to configure a custom http code so that upstream servers  
can  
send that code if it wants to send nginx to upstream ?

Thanks  
Frank

---

<div class="post-metadata">

**Author:** ![fjlj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@fjlj](https://www.ruby-forum.com/u/fjlj)\
**Post date:** [December 10, 2015, 8:13pm UTC](https://www.ruby-forum.com/t/next-upstream-based-on-custom-http-code/243611/2 "2015-12-10T20:13:51Z")

</div>

## Like… 503? To me ‘server wants to make another upstream dealing with the request’ sounds very much like ‘Service Unavailable’.

_B. R._

---

<div class="post-metadata">

**Author:** ![fjlj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@fjlj](https://www.ruby-forum.com/u/fjlj)\
**Post date:** [December 10, 2015, 9:20pm UTC](https://www.ruby-forum.com/t/next-upstream-based-on-custom-http-code/243611/3 "2015-12-10T21:20:26Z")

</div>

No, 503 may be a legitimate error from upstream that nginx needs to pass  
to  
client.  
I am thinking some unused code , say, 590.

---

<div class="post-metadata">

**Author:** ![fjlj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@fjlj](https://www.ruby-forum.com/u/fjlj)\
**Post date:** [December 11, 2015, 9:24am UTC](https://www.ruby-forum.com/t/next-upstream-based-on-custom-http-code/243611/4 "2015-12-11T09:24:20Z")

</div>

If the upstream refuses to process a request, you might wish to emulate  
an  
unavailable service or a lack of response (timeout). Backend up and  
working  
are expected to process requests.  
Switching between legitimate errors and faked one will be done by  
monitoring backend logs.

## There is no such thing as a ‘Coffee Break’ HTTP code. :oP

_B. R._

---

<div class="post-metadata">

**Author:** ![fjlj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@fjlj](https://www.ruby-forum.com/u/fjlj)\
**Post date:** [December 11, 2015, 10:06am UTC](https://www.ruby-forum.com/t/next-upstream-based-on-custom-http-code/243611/5 "2015-12-11T10:06:24Z")

</div>

Here is my flow: client - nginx - upstream - real upstream

Upstream is getting the response from the ‘real’ upstream. So if real  
upstream is wrong, nginx will get standard 5xx from upstream and in this  
case I don’t really want nginx to try next upstream because it will hit  
the  
same bad real upstream with the same error code. In other cases where  
real  
upstream is good but one upstream is having too much load or wants to  
finish up in flight requests then go down for maintenance , is it  
possible  
for upstream to send a soft error code to nginx to tell it try next  
upstream.?
