session persistance with IP hash

Brian Pugh project722 at gmail.com
Wed Jul 27 20:55:11 UTC 2016


Reinis Rozitis said:
Yes, you can use different hash mechanisms/keys (for example specific
cookies etc):
https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#hash

There are also some third-party sticky cookie modules.

Took a look at the link, but I have no idea what that would look like in my
upstream stanza. Can you provide an example of what that would look like if
I had 3 different backend servers and wanted to ensure that my hash was
based on a cookie, or based on just a hash that provided a different
backend server per session?


So in theory I could also just run a daily script to weight the servers
differently or change the server order to manipulate how the hash is
calculated? Has that ever been done with success?

On Wed, Jul 27, 2016 at 3:44 PM, Reinis Rozitis <r at roze.lv> wrote:

> My understanding is that the ip_hash directive is responsible for session
>> persistence. My questions are:
>> 1) How long does it last? For example, if I connect and my ip hash tells
>> nginx to connect to backend3, will my source IP be forever tied to backend
>> 3?
>>
>
> If your IP doesn't change and all the servers are up, you will most likely
> always land on the same backend server.
> http://nginx.org/en/docs/http/ngx_http_upstream_module.html#ip_hash
>
>
> 2) Is there another way to acheive session persistence other than ip hash
>> and other than purchasing plus edition?
>>
>
> Yes, you can use different hash mechanisms/keys (for example specific
> cookies etc):
> https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#hash
>
> There are also some third-party sticky cookie modules.
>
>
> I personally preffer to use centralised cache storage (memcache/redis etc)
> so it doesn't matter on which server the user lands and they can be used in
> roundrobin fashion.
>
>
> 3) Is there an ip hash "cache" or something I can clean out periodically
>> to force the source IP to get a new hash and therefore a chance to connect
>> to a different server?
>>
>
> The standard nginx hash mechanisms don't have any inbuilt "cache". In case
> of ip_hash you can change the upstream server order (though it will swap
> arround all the users not only particular remote addr).
>
> rr
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20160727/33d0c67a/attachment.html>


More information about the nginx mailing list