Welcome! Log In Create A New Profile

Advanced

Re: session persistance with IP hash

Reinis Rozitis
July 27, 2016 06:04PM
>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?


With the vanilla nginx it would be something like (and for example let's say
your cookie name is BACKEND):

upstream backend {
hash $cookie_BACKEND;
server backend1:80;
server backend2:80;
server backend3:80;
}


The problem with this (if it matters) is that there is no (pre)defined value
of the cookie BACKEND which would specifically route particular client to
particular backend - I mean for example if you use values 'backend1',
'backend2', 'backend3' the hashed keys might (or not) aswell all point to
the same backend server.
So unless you find 3 values which for sure point to different backends the
load/users might not be evenly distributed (in general it is the same as
with ip_hash if the end-users don't have very distinct IPs or for example
are in the same subnet all the users will land on the same backend (as per
documentation - "The first three octets of the client IPv4 address are used
as a hashing key.")). It shouldn't be too hard though.

Of course if the values differ (for each user a different cookie) in longer
run the requests will be somewhat evenly distributed.

As a module you can try this
https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/overview but as
it was mentioned in previous mail by Robert the quality might vary and if
you want a better controlable user distribution Lua could be also an option.


p.s. In case of the bare nginx the first request is "problematic" since
there won't be any cookie so it will always land on one backend and later if
the cookie gets generated by backend application the user might get "moved"
to a different backend server. (eg thatš why it is better to use a hash key
like ip / url or browser agent header which is known to nginx immediately)

rr


_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

session persistance with IP hash

Brian Pugh July 27, 2016 04:22PM

Re: session persistance with IP hash

Robert Paprocki July 27, 2016 04:36PM

Re: session persistance with IP hash

Reinis Rozitis July 27, 2016 04:46PM

Re: session persistance with IP hash

Brian Pugh July 27, 2016 04:56PM

Re: session persistance with IP hash

Reinis Rozitis July 27, 2016 06:04PM

Re: session persistance with IP hash

Brian Pugh July 27, 2016 09:24PM

Re: session persistance with IP hash

Robert Paprocki July 27, 2016 09:46PM

Re: session persistance with IP hash

Brian Pugh July 28, 2016 10:34AM

Re: session persistance with IP hash

Robert Paprocki July 28, 2016 12:08PM

Re: session persistance with IP hash

Brian Pugh July 28, 2016 12:42PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 236
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready