Nginx and conditional proxy_next_upstream directive

I want nginx to prevent trying the next upstream if the request is a
request and the request just timed out. POSTs should only be repeated on
error. I tried this config to implement it:

if ($request_method = POST) {
proxy_next_upstream error;

But this fails with:

nginx: [emerg] “proxy_next_upstream” directive is not allowed here…

I tried it within location context as well as server context, but got
the same error while configurations like these are running fine:

if ($request_method = POST) {
return 403;

Or just (without if):

proxy_next_upstream error;

Is this a bug in nginx or is this related to “if is evil”?

What is the best way to implement the above functionality with ningx?

Posted at Nginx Forum:,264486,264486#msg-264486

Is this question to stupid or has nobody an answer on it? :wink:

I just think a POSTs are not idempotent and should never be repeated for
technical reason. Is there any change to configure nginx in a way to try
next upstream only if the first one really failed when using POST
Timed out requests on one upstream could potentially still be processed
an application. Handing this request over to the next upstream must not
cause the same result as the first upstream since POSTs are not

Any help would be appreciated.

Posted at Nginx Forum:,264486,264734#msg-264734

FYI, possible related issue on nginx-dev mail list:,264637,264637#msg-264637

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs