Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 459
witsches Avatar asked Oct 19 '12 07:10

witsches


People also ask

What is Ip_hash in Nginx?

With ip-hash, the client's IP address is used as a hashing key to determine what server in a server group should be selected for the client's requests. This method ensures that the requests from the same client will always be directed to the same server except when this server is unavailable.

What is Nginx upstream module?

NGINX is a load-balancing tool widely used in the IT industry. It is a web server that can be used as a reverse proxy, mail proxy, or an HTTP cache. Upstream is a module used in NGINX to define the servers to be load balanced.

How does upstream work Nginx?

upstream defines a cluster that you can proxy requests to. It's commonly used for defining either a web server cluster for load balancing, or an app server cluster for routing / load balancing. Save this answer.

What is upstream address in Nginx?

upstream. Defines the address and other parameters of a server. The address can be specified as a domain name or IP address, with an optional port, or as a UNIX-domain socket path specified after the “ unix: ” prefix. If a port is not specified, the port 80 is used.


1 Answers

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

like image 168
Sergey Budnevitch Avatar answered Sep 23 '22 23:09

Sergey Budnevitch