=:精确匹配检查
~:正则表达式模式匹配,区分字符大小写
~*:正则表达式模式匹配,不区分字符大小写
^~:URL的前半部分匹配,不支持正则表达式
要想使用echo,编译时要添加echo-nginx-module模块,下载地址:https://github.com/openresty/echo-nginx-module
编译nginx时添加:–add-module= /path/to/echo-nginx-module
匹配优先级:= > ^~ > ~ 、~* (这两个优先级相同,谁在前面就匹配谁) > 不带任何符号的location
等号优先级最高
(1) location = /index.html {
echo “this is = index.html”;
}
(2) location /index.html {
echo “/index.html”;
}
(3) location ^~ /img/ {
echo “^~img”;
}
(4) location ~* \.(html|png|jpg|jpeg)$ {
echo “~*.img”;
}
(5) location /doc/ {
echo “doc”;
}
http://192.168.10.202/index.html 匹配的是(1)
http://192.168.10.202/img/index.html 匹配的是(3)
http://192.168.10.202/doc/index.html 匹配的是(4)