Does Nginx support cookie which acts as a load balance?

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

Hi,

On Fre 04.01.2008 01:23, Joe wrote:

Hi All

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?

Nginx have not this possibility yet.

A possible solution is to use haproxy[1] as upstream target and let
haproxy[1] make the cookie stickyness

Cheers & hth

Aleks

[1] http://haproxy.1wt.eu/

Joe ha scritto:

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.

It’s the “same” blog service?

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?

Rewrite the blog application if this happens, since they are not
restful.

State must not be stored locally.

Thanks
Joe

Manlio P.

Joe wrote:

Assuming the domain name is blog.abc.com, when user sign in server A

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

Evan M. wrote:

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:

I think you forgot to add the attachment :wink:
I tried using mod_userid and hash $uid_got, but unfortunately to no
avail :frowning:
Your patch would be very useful to me.

regards

Khorne

Michael Rzechonek ha scritto:

Evan M. wrote:

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:

I think you forgot to add the attachment :wink:
I tried using mod_userid and hash $uid_got, but unfortunately to no
avail :frowning:
Your patch would be very useful to me.

Give a look at:
http://hg.mperillo.ath.cx/nginx/mod_parsed_vars

and
http://article.gmane.org/gmane.comp.web.nginx.english/3001

The current version requires a small patch to nginx.

P.S.:
unlike the Evan’s patch, I have written a custom parser for the cookies.

I was not aware of the ngx_http_parse_multi_header_lines function, but
cookies format is a mess so a custom parser may be a better solution.

regards

Khorne

Manlio P.

Michael Rzechonek ha scritto:

Good!

Make sure to read the README and TODO, since there are some limitations
and things that should be implemented.

For those interested, Gentoo ebuild with hash and parsed_vars modules is
available at
http://leto.homedns.org/svn/khorne-overlay/www-servers/nginx/


Khorne

Manlio P.

Manlio P. wrote:

Give a look at:
http://hg.mperillo.ath.cx/nginx/mod_parsed_vars

and
http://article.gmane.org/gmane.comp.web.nginx.english/3001

The current version requires a small patch to nginx.

Thanks for the fast reply - works like a charm!

For those interested, Gentoo ebuild with hash and parsed_vars modules is
available at
http://leto.homedns.org/svn/khorne-overlay/www-servers/nginx/


Khorne