Nginx and conditional proxy_next_upstream directive

I want nginx to prevent trying the next upstream if the request is a
POST
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
always
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”?
(If is Evil… when used in location context | NGINX)

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

Posted at Nginx Forum:

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
a
technical reason. Is there any change to configure nginx in a way to try
the
next upstream only if the first one really failed when using POST
requests?
Timed out requests on one upstream could potentially still be processed
by
an application. Handing this request over to the next upstream must not
cause the same result as the first upstream since POSTs are not
idempotent.

Any help would be appreciated.

Posted at Nginx Forum:

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