1

I'm using Nginx as a load balancer between two webservers.

I noticed that, when one of the two webservers is down, GET requests are well forwarded to the second one, while POST are not:

Here is the message I got with GET request, it is forwarded to the second server, and end with a proper 200:

"xx.xx.xx.xx" 502 na.mysite.net [...] "server-01:443, server-02:443" [...] 502, 200

Here is the message I got with POST request, it ends with a 502:

"xx.xx.xx.xx" 502 na.mysite.net [...] "server-01:443" [...] 502

The upstream servers are defined that way:

upstream my-site{
        keepalive 16;

        # Web backend servers
        server server-01:443 max_fails=0;
        server server-02:443 max_fails=0;
}

Before you ask, I don't use max_fails nor fail_timeout because some requests can take a very, very long time (minutes) so I don't want them to be considerate as failed.

I would like to have the same behavior for POST requests, but I can't find information regarding this on Google or Nginx's documentation.

Any help is welcomed, thank you in advance!

2 Answers 2

0

I got it, this is by design to prevent data corruption:

non_idempotent normally, requests with a non-idempotent method (POST, LOCK, PATCH) are not passed to the next server if a request has been sent to an upstream server (1.9.13); enabling this option explicitly allows retrying such requests;

0

To make the nginx server forward the request to the next server you need to use non_idempotent option.

From nginx documentation (proxy_next_upstream section):

non_idempotent

normally, requests with a non-idempotent method (POST, LOCK, PATCH) 
are not passed to the next server if a request has been sent to an 
upstream server (1.9.13); enabling this option explicitly allows 
retrying such requests;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .