Jérôme Loyet
August 15, 2011 05:06AM
2011/8/14 Kamil Gorlo <kgs4242@gmail.com>:
> Hi guys!

Hi

>
> I have Nginx configured as load balancer to some number of application
> servers. I need to configure Nginx in such a way that if there is
> cookie set in request ("server_id=<some_number>"), I have to forward
> this request to backend identified by <some_number> - if there is no
> cookie set, every server could be chosen with equal probability to
> serve request.
>
> So my need is something similar to functionality given by nginx
> upstream hash module. But I want to have more control of which server
> has to be chosen. It has to be exact server pointed by variable (in
> this case: cookie value) - no hash calculations.
>
> Something like this:
>
> upstream {
>   server app-1;
>   server app-2;
>   server app-3;
>   choose $cookie_SERVER_ID;
> }
>
> When cookie "SERVER_ID" is present in request and it is number from 1
> to 3 (which means order in server listed in config or suffix in server
> name), it should suggest that this particular request should be
> forwarded to app-<NUM> server. But when there is no cookie, standard
> round-robin algorithm could be used for balancing. Also when some
> server is dead (even if it is chosen by variable from cookie) request
> should be forwarded to next live backend.
>
> How to do this? Is writing own module (similar to upstream hash) the
> simplest idea? Or is there something more clever?

nginx sticky module (http://code.google.com/p/nginx-sticky-module/)
does exactly what you're looking for.

++ Jerome

>
> Best regards,
> Kamil
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>

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

Routing based on cookies

Kamil Gorlo August 14, 2011 04:42PM

Re: Routing based on cookies

leepengg August 14, 2011 07:18PM

Re: Routing based on cookies

Kamil Gorlo August 15, 2011 06:00AM

Re: Routing based on cookies

Jérôme Loyet August 15, 2011 05:06AM

Re: Routing based on cookies

Kamil Gorlo August 15, 2011 06:02AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 366
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready