*location匹配的分类和优先级
匹配分类
1、精确匹配
location = / 对字符串进行完全匹配,必须完全符号
2、正则匹配
^~ 前缀匹配,以什么为开头
-区分大小写的匹配
-*不区分大小写
!~区分大小写的取反
!~*不区分大小写的取反
3、一般匹配
location /
优先级
优先级总结:从高到低
- 精确匹配:location = 完整路径 {}
- 正则匹配:location ^~ 匹配内容 {}
- 正则匹配:location ~ 匹配内容 {} ;location ~* 匹配内容 {}
- 一般匹配:location /部分起始位置
- 通用匹配:location /
实际网站中的使用规则:
1、精确匹配网站的首页
location = / {
root html;
index index.html index.html index.php;
}
2、必选规则: 处理静态请求的页面
用来匹配静态页面
location ^- /static/ {
root /web/static/;
index index.html index.htm;
}
访问图片或者指定的后缀名:
location -* \ .(jpg|png|png|peg|css|php)$ {
roo