Search code examples
nginxload-balancing

about ip_hash in nginx upstream module


I want to replace pound with nginx as loadbalancer and all tests look fine so far. I will do a typical upstream configuration like this:

upstream backend {
  ip_hash;
  server   backend1.example.com;
  server   backend2.example.com;
  server   backend3.example.com;
}

There are now 2 questions left open:

  1. How long does this stickyness last? Is there a ttl to be defined somewhere?
  2. Does the stickyness survive restarts and/or reloads of nginx?

I could not find the answer in the nginx wiki. Links to official docs are welcome.


Solution

  • It is based on client source ip address hash and as long as you have same set of backends stickiness will persist.

    http://nginx.org/en/docs/http/ngx_http_upstream_module.html#ip_hash