session persistance with IP hash

Robert Paprocki rpaprocki at
Thu Jul 28 01:44:49 UTC 2016

> I'm not as concerned with what server its routed to as much as I am
> concerned with the client session "sticking" to the server it was routed
> to. And I really do not know enough about how to use cookie based hashing.
> In order to have cookie bashed hashing would the cookie need to be common
> among all pages at the target URL in order to stick the session to a
> particular server for the duration of that session?

Assuming you're using a cookie to track the session, the cookie shouldn't
change depending on what URI the user is accessing.

> (And, I assume cookie bashed hashing is not like ip hash in that you are
> only stuck to a particular server for the duration of that browser session?)

Depends on how long the cookie lives on the browser. If the cookie never
changes and doesn't expire when the browser closes, the backend wouldn't
change (again, assuming nothing changed about the backend servers).

It doesn't matter what is used to build the hash key - cookie, ip,
whatever. As long as that value doesn't change, and nothing changes about
your backends, the client will hit the same backend every time. Guaranteed.

> Also, what is the logic behind "round-robin" or is that the same as
> ip_hash? For instance, If I have a client at that's assigned
> to backend 3, then, 100 more clients come along on the same subnet, they
> will all land on backend 3. Next client comes along, what
> determines whether it lands on backend1 or backend2? Or, is there a chance
> it could also land on backend3?

Round robin means that each backend will be used in turn, regardless of the
client. For example, if you have 3 backends:

request 1 -> backend1
request 2 -> backend2
request 3 -> backend3
request 4 -> backend1
request 5 -> backend2

This goes on forever, regardless of the client IP. (Of course, this is
relative if you are using server weights - see the example at for a
round robin example with weights). If you want session persistence, then
round robin balancing is not for you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list