Does Nginx support cookie which acts as a load balance?

Evan Miller emmiller at gmail.com
Thu Jan 3 21:53:18 MSK 2008


Joe wrote:
> Hi All
> I setup a load balance by using Nginx, there have several Linux boxes 
> running PHP+MySQL as the backend servers, they're all for Blog service.
> 
> -------+-------+-----+-----+-----+---
>        |       |     |     |     |      +--+--+  +-+-+ +-+-+ +-+-+ +-+-+
>     | LB1 |  | A | | B | | C | | D |
>     +-----+  +---+ +---+ +---+ +---+
>     Nginx    several Blog servers
> 
> Assuming the domain name is blog.abc.com, when user sign in server A 
> with his own username and password, if he try to access blog.abc.com 
> again, it's possible that his requests will be transferred to server B 
> or others, then I think this user will be asked for input his username 
> and password again on server B or others. So my question is how can I 
> configure Nginx to let this user access server A again when he access 
> blog.abc.com until he sign out?
> 
> 
> Thanks
> Joe
> 
> 

I did something similar a while ago. The attached patch adds variables 
for accessing cookies ($http_cookie_foo => "foo" cookie). You can use it 
in conjunction with the Upstream Hash module:

http://wiki.codemongers.com/NginxHttpUpstreamRequestHashModule

Then your config would be something like:

upstream backend {
     server a...;
     server b...;
     hash $http_cookie_username;
}

Evan
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nginx-0.6.24-cookies.patch
URL: <http://nginx.org/pipermail/nginx/attachments/20080103/2dd6e14e/attachment.ksh>


More information about the nginx mailing list