相信信息如下:http://nginx.org/en/docs/http/ngx_http_core_module.html#location
location 的语法匹配的格式:
location [=|~|~*|^~] patt {
}
location = patt {} [精准匹配]
location patt{} [一般匹配]
location ~ patt{} [正则匹配]
1、 匹配的规则为:
先去匹配精准匹配,如果精辟匹配不成功则会去匹配一般匹配,再次为正则匹配。
匹配实例为:
1) 精准匹配
location = / {
root html;
index a.html index.html index.htm;
}
2) 一般匹配
location =/ {
root html;
index a.html index.html index.htm;
}
3)、 正则匹配
location ~ image {
root /var/www/;
index index.html;
}
4) 正则匹配
location / image {
root /var/www/;
index index.html;
}
注意 : 1)、 ~ image 正则匹配时会把image目录带上,在root把最后的image的目录去掉。
正则匹配时匹配上第一个就会返回。
2) 在一般匹配时匹配记忆最长的结果