
root 与 alias 的区别
location ^~ /static {
root /home/lushijie/www.test.com;
}
#http://120.27.105.225/static/a.gif
#在 /home/lushijie/www.test.com/static 目录下寻找 a.gif
location ^~ /resource {
alias /home/lushijie/www.test.com;
}
#http://120.27.105.225/resource/a.gif
#在 /home/lushijie/www.test.com 目录下寻找 a.gif
= (精确匹配)
= 进行精确匹配,如果发现精确匹配,nginx停止搜索其他匹配
location = /71team {
echo '规则1-1 = /71team';
}
location = /71team123 {
echo '规则1-2 = /71team123';
}
#http://120.27.105.225/71team 规则1-1 = /71team
#http://120.27.105.225/71team123 规则1-2 = /71team123
#http://120.27.105.225/71team12 Not Found
#http://120.27.105.225/71team/ Not Found HTTP段 (#此时 server_name_in_redirect off;)
^~(开头最长匹配)
^~ 普通开头字符最长匹配,长的块规则将被优先和查询匹配,如果该项匹配还需去看有没有更长的匹配
location ^~ /72team {
echo '规则2-1 ^~ /72team';
}
location ^~ /72team123 {
echo '规则2-2 ^~ /72team123';
}
#http://120.27.105.225/72team 规则2-1 ^~ /72team
#http://120.27.105.225/72team123 规则2-2 ^~ /72team123
#http://120.27.105.225/72team12 规则2-1 ^~ /72team
#http://120.27.105.225/72team/ 规则2-1 ^~ /72team
空 (最长匹配)
/ 表示普通字符匹配, 长的块规则将被优先和查询匹配,如果该项匹配还需去看有没有更长的匹配
location /75team {
echo '规则5-1 /75team';
}
location /75team123 {
echo '规则5-2 /75team123';
}
#http://120.27.105.225/75team 规则5-1 /75team
#http://120.27.105.225/75team123 规则5-2 /75team123
#http://120.27.105.225/75team12 规则5-1 /75team
#http://120.27.105.225/75team/ 规则5-1 /75team
~ / ~*(区分 / 不区分大小写正则匹配)
如果找到相应的匹配,则nginx停止搜索其他匹配
location ~ /74team {
echo '规则4-1 ~ /74team ';
}
location ~ /74team123 {
echo '规则4-2 ~ /74team123';
}
#http://120.27.105.225/74team 规则4-1 ~ /74team
#http://120.27.105.225/74team123 规则4-1 ~ /74team
#http://120.27.105.225/74team12 规则4-1 ~ /74team
#http://120.27.105.225/74team/ 规则4-1 ~ /74team
~* 亦如是
冲突配置
^~与空 如果重复了,会有冲突!