# Directive proxy\_next\_upstream doesn't work?

**URL:** <https://www.ruby-forum.com/t/directive-proxy-next-upstream-doesnt-work/215283>\
**Category:** NGINX\
**Created:** [December 29, 2011, 8:46am UTC](https://www.ruby-forum.com/t/directive-proxy-next-upstream-doesnt-work/215283 "2011-12-29T08:46:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [December 29, 2011, 8:46am UTC](https://www.ruby-forum.com/t/directive-proxy-next-upstream-doesnt-work/215283/1 "2011-12-29T08:46:41Z")

</div>

nginx conf is:

http {  
large\_client\_header\_buffers 8 8k;

proxy\_buffers 8 8K;  
proxy\_buffer\_size 8K;

open\_file\_cache max=1000 inactive=20s;  
open\_file\_cache\_valid 30s;  
open\_file\_cache\_min\_uses 2;  
open\_file\_cache\_errors on;

upstream backend {  
server 10.10.2.100:8088 max\_fails=200 fail\_timeout=10;  
server 10.10.2.101:8088 max\_fails=200 fail\_timeout=10;  
server 10.10.2.102:8088 max\_fails=200 fail\_timeout=10;  
server 10.10.2.103:8088 max\_fails=200 fail\_timeout=10;  
}

server {  
listen 80;  
server\_name \_;  
keepalive\_timeout 60;  
proxy\_set\_header Host $http\_host;

proxy\_connect\_timeout 10;  
proxy\_read\_timeout 10;  
proxy\_next\_upstream error http\_500 http\_502 http\_503  
http\_504;  
add\_header P3P “CP=CAO PSA OUR”;  
add\_header Cache-Control  
“must-revalidate,no-cache,private”;

location / {  
proxy\_pass [http://backend](http://backend);  
}  
}  
}

On my production, in the cases a server of upstream response http\_504,  
but the request doesn’t to be transmitted to the next server, nginx  
response http 504 to client.

Posted at Nginx Forum:

> **[Directive proxy\_next\_upstream doesn't work?](https://forum.nginx.org/read.php?2,220648,220648#msg-220648)**
>
> nginx conf is: http { large\_client\_header\_buffers 8 8k; proxy\_buffers 8 8K; proxy\_buffer\_size 8K; open\_file\_cache max=1000 inactive=20s; open\_file\_cache\_valid

---

<div class="post-metadata">

**Author:** ![defage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@defage](https://www.ruby-forum.com/u/defage)\
**Post date:** [December 29, 2011, 8:47am UTC](https://www.ruby-forum.com/t/directive-proxy-next-upstream-doesnt-work/215283/2 "2011-12-29T08:47:19Z")

</div>

My ngx is last stable version.  
centos 5.4 x86\_64

Posted at Nginx Forum:

> **[Re: Directive proxy\_next\_upstream doesn't work?](https://forum.nginx.org/read.php?2,220648,220649#msg-220649)**
>
> nginx conf is: http { large\_client\_header\_buffers 8 8k; proxy\_buffers 8 8K; proxy\_buffer\_size 8K; open\_file\_cache max=1000 inactive=20s; open\_file\_cache\_valid

---

<div class="post-metadata">

**Author:** ![defage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@defage](https://www.ruby-forum.com/u/defage)\
**Post date:** [December 29, 2011, 9:34am UTC](https://www.ruby-forum.com/t/directive-proxy-next-upstream-doesnt-work/215283/3 "2011-12-29T09:34:12Z")

</div>

Hello!

On Thu, Dec 29, 2011 at 02:45:42AM -0500, defage wrote:

> open\_file\_cache\_min\_uses 2;  
> server {  
> add\_header Cache-Control  
> response http 504 to client.  
> A request is passed to a next server only if not all (alive)  
> upstream servers were tried yet. Otherwise response from last  
> tried server will be returned.

Maxim D.

---

<div class="post-metadata">

**Author:** ![defage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@defage](https://www.ruby-forum.com/u/defage)\
**Post date:** [December 29, 2011, 10:08am UTC](https://www.ruby-forum.com/t/directive-proxy-next-upstream-doesnt-work/215283/4 "2011-12-29T10:08:13Z")

</div>

you mean at that moment all of upstream server has to tried,and it  
reponse 504? but at that moment only one app server’s log throw error  
info.  
A part of access\_log like:  
10.001 10.001 /cas/login 10.10.2.100:8080 504  
10.001 10.001 /cas/login 10.10.2.100:8080 504

If pass to all servers, the log is like below:?  
10.001 10.001 /cas/login 10.10.2.100:8080, 10.10.2.101:8080,  
10.10.2.102:8080, 10.10.2.103:8080 504

the problem is my app server 's log show ,at that moment only one server  
of upstream have 504 error.

Posted at Nginx Forum:

> **[Re: Directive proxy\_next\_upstream doesn't work?](https://forum.nginx.org/read.php?2,220648,220659#msg-220659)**
>
> nginx conf is: http { large\_client\_header\_buffers 8 8k; proxy\_buffers 8 8K; proxy\_buffer\_size 8K; open\_file\_cache max=1000 inactive=20s; open\_file\_cache\_valid

---

<div class="post-metadata">

**Author:** ![defage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@defage](https://www.ruby-forum.com/u/defage)\
**Post date:** [December 29, 2011, 1:36pm UTC](https://www.ruby-forum.com/t/directive-proxy-next-upstream-doesnt-work/215283/5 "2011-12-29T13:36:40Z")

</div>

Hello!

On Thu, Dec 29, 2011 at 04:07:41AM -0500, defage wrote:

> the problem is my app server 's log show ,at that moment only one server  
> of upstream have 504 error.

It looks like you are trying to handle timeouts, not 504 returned  
by an upstream server. You have to specify “timeout” in  
proxy\_next\_upstream directive, not “http\_504”.

Or better just remove the proxy\_next\_upstream directive from your  
config, default value “error timeout” is good enough in most  
cases.

Maxim D.
