location匹配首先考虑匹配的精确度,比如
location ^~ /m/ { }
location ^~ /m/1/2 { }以上两行,即便匹配/m/放在上方,依然会先匹配到更精确的/m/1/2
if的匹配(假如都能都匹配成功):
当两个if块中都是rewrite时,会先匹配上方
当两个if块内部都是proxy_pass时,会先匹配下方的
当一个是rewrite一个是proxy_pass会先匹配rewrite,无论上下
location / {
root www;
if ($remote_addr ~* "^(124.193.66.139)"){
rewrite ^(.*)$ http://www.motie.com;
# proxy_pass http://test1Server;
}
if ($request_method = GET ){
# rewrite ^(.*)$ http://www.baidu.com;
proxy_pass http://testServer;
}
index index.html index.htm;
}以上在Ninx1.2、1.6测试
原文地址:http://liuyuan.blog.51cto.com/740753/1902421