problem about set variable according rewrite rule whithout if{}

yahwist yangchunyu at soufun.com
Fri Sep 26 14:10:24 MSD 2008


I use apache2.2.8 as my web proxy server. I use the rewrite rule to implement 
according article id's last number to assign 

user's request to different domain. the apache rules is

RewriteRule  ^/([0-9]+)([0-9])/(.*)	http://load$2.test.com/$1$2/$3 [P,L,NC]
which can rewrite
http://load.test.com/1210019701/test.htm to 
http://load1.test.com/1210019701/test.htm
http://load.test.com/1210019707/test.htm to 
http://load7.test.com/1210019701/test.htm

Now, I want to use nginx, I have a working solution and a failed solution, it 
have a lot of rules in my config, working 

solution is so cockamamie, need a lot of if{} and set. failed solution only 
need one set. I want to know how can failed 

solution working.

working solution:
location  / {
if ($uri ~* ^/([0-9]+)([0-9])/(.*)) {
    set $loadurl load$2.test.com;
    rewrite  ^/([0-9]+)([0-9])/(.*)     /$1$2/$3 break;
    proxy_pass $loadurl;
    }
}

failed solution:
location  / {
rewrite  ^/([0-9]+)([0-9])/(.*)     /$1$2/$3 break;
set $loadurl load$2.test.com;
proxy_pass $loadurl;
}






More information about the nginx mailing list