Nginx and conditional proxy_next_upstream directive

dontknowwhoiam nginx-forum at
Thu Feb 11 15:14:36 UTC 2016

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"?

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

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

More information about the nginx mailing list