Reputation: 135
I'm willing to use Nginx as a reverse proxy and loadbalancer.
I have 2 servers with 2 differents versions of my application. I.E. if user have V1 on his computer, he has to go on server 1. If he has V2, server 2.
I used some $_GET parameters to redirect the user to the corresponding server with this code (if not V1, then it's V2) :
if ($args ~* V=1) {
proxy_pass http://server1;
break;
}
proxy_pass http://server2;
This works well. But I got a problem with some AMF requests (Flash needed) : I can't set a $_GET parameter or a header. So I tried to use cookies, but nothing seems to work.
if ($http_cookie ~ 'V=1') {
proxy_pass http://server1;
break;
}
if ($cookie_VER ~ 'V=1'){
proxy_pass http://server1;
break;
}
I can't use the HttpMapModule because I also need the redirection with $_GET parameters...
Is there any way to do what I want, or am I going the wrong way ?
Upvotes: 1
Views: 2455
Reputation: 1027
Actually, your second example should work if I understand you correctly but there is small mistake there. If you can set a cookie called V1 for app 1, and set another cookie as V2 for app 2, then you can use that code as follows:
if ($http_cookie ~* 'V1') {
proxy_pass http://server1;
break;
}
if ($http_cookie ~* 'V2'){
proxy_pass http://server2;
break;
}
Please check the bottom of my article on virtual.conf configuration directives for reverse proxy setup.
Upvotes: 1