Choose upstream based in a cookie

Dayo nginx-forum at
Thu Feb 17 18:23:38 MSK 2011

I don't know if that will work (see

This will almost certainly work:

location / {
		set_by_lua $backend_ip '
			if ngx.var.cookie_memberid ~= "" and ngx.var.cookie_memberid ~= nil
				return ""
			elseif ngx.var.cookie_clientid ~= "" and ngx.var.cookie_clientid ~=
nil then
				return ""
				return ""
		proxy_pass http://$backend_ip;

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:,170775,176154#msg-176154

More information about the nginx mailing list