2011年2月17日星期四

Re: Choose upstream based in a cookie

I don't know if that will work (see http://wiki.nginx.org/IfIsEvil)

This will almost certainly work:

[code]
location / {
set_by_lua $backend_ip '
if ngx.var.cookie_memberid ~= "" and ngx.var.cookie_memberid ~= nil
then
return "10.10.10.10"
elseif ngx.var.cookie_clientid ~= "" and ngx.var.cookie_clientid ~=
nil then
return "10.10.10.15"
else
return "10.10.10.20"
end
';
proxy_pass http://$backend_ip;
}
[/code]

Needs 3rd party lua module.

I only just discovered it myself and starting to learn lua. Seems worth
it as it opens up a lot of possibilities without getting into the if is
evil issues.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,170775,176154#msg-176154


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

没有评论:

发表评论