1

I've set up NGINX to load-balance requests to my web app. One front end server passes requests to two backend servers. All works fine.

However, I have been using the ip_hash directive to ensure users are served by the same server each time. This doesn't seem to be working - requests alternate between the two backend servers, and this is causing problems with user sessions.

The config should be quite simple, so I don't know where this is going wrong - any ideas appreciated.

upstream webservers  {
  ip_hash;
  server node1.mysite.com;
  server node2.mysite.com;
  server localhost:8080 backup;
}

server {
    listen 80;

    server_name www.mysite.com;

    location / {

        proxy_set_header    Host                $host;
        proxy_set_header    X-Real-IP           $remote_addr;
        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto   $scheme;
        proxy_pass  http://webservers;

    }

}
1
  • Can you post factual information about your issue ? Like the relevant access logs ... Nov 26, 2014 at 22:22

2 Answers 2

1

I found a solution, of sorts.

It seems that ip_hash is incompatible with the backup directive, and possibly with any other directive in the upstream block.

Once I removed the backup line, ip_hash works as it should.

However, this seems strange. I'm using a recent version of NGINX - 1.6 - and I can't find anything in the more recent docs to say that ip_hash and backup directives are still incompatible.

0

backup marks the server as a backup server. Connections to the backup server will be passed when the primary servers are unavailable. The parameter cannot be used along with the hash and random load balancing methods. you can find it at this link http://nginx.org/en/docs/stream/ngx_stream_upstream_module.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.