Nginx中location
2016-12-28 23:51
260 查看
location
匹配规则
~ 表示执行一个正则匹配,区分大小写
~* 表示执行一个正则匹配,不区分大小写
^~ 表示普通字符匹配,一旦匹配则不会再去匹配其他,一般用于匹配目录
= 进行普通字符精确匹配
@ 定义一个命名的location,使用内部定向时,例如error_page
优先级
如果使用了=号,则匹配到普通字符就停止匹配其他;
然后其他没有使用=号的常规字符,进行最长匹配;
如果匹配使用了^~,则停止匹配其他;
正则表达式是依照配置文件中的顺序进行匹配的;
如果没有正则表达式或者正则表达式没有被匹配的情况下,则匹配程度最高的逐字匹配指令会被使用
location 实例
1、=
location = / {
root html;
index index.html;
allow all;
}
这样是能只匹配/文件的(可以将allow改成deny测试),所以会找不到index.html文件,下面可以正常访问
location = /index.html {
root html;
index index.html;
allow all;
}
=用于普通字符的精确匹配。要匹配目录不建议使用=
2、^~
location ^~ / {
root html;
index index.html;
allow all;
}
能够匹配到以/开始的请求,停止匹配其他location
^~用于匹配目录
3、~*
location ~* .png$ {
root /usr/share/nginx/test10;
}
匹配规则
~ 表示执行一个正则匹配,区分大小写
~* 表示执行一个正则匹配,不区分大小写
^~ 表示普通字符匹配,一旦匹配则不会再去匹配其他,一般用于匹配目录
= 进行普通字符精确匹配
@ 定义一个命名的location,使用内部定向时,例如error_page
优先级
如果使用了=号,则匹配到普通字符就停止匹配其他;
然后其他没有使用=号的常规字符,进行最长匹配;
如果匹配使用了^~,则停止匹配其他;
正则表达式是依照配置文件中的顺序进行匹配的;
如果没有正则表达式或者正则表达式没有被匹配的情况下,则匹配程度最高的逐字匹配指令会被使用
location 实例
1、=
location = / {
root html;
index index.html;
allow all;
}
这样是能只匹配/文件的(可以将allow改成deny测试),所以会找不到index.html文件,下面可以正常访问
location = /index.html {
root html;
index index.html;
allow all;
}
=用于普通字符的精确匹配。要匹配目录不建议使用=
2、^~
location ^~ / {
root html;
index index.html;
allow all;
}
能够匹配到以/开始的请求,停止匹配其他location
^~用于匹配目录
3、~*
location ~* .png$ {
root /usr/share/nginx/test10;
}
相关文章推荐
- Nginx location&rewrite
- nginx配置location总结及rewrite规则写法
- nginx location匹配规则
- nginx的location配置详解
- 服务器-Nginx-Location配置
- nginx的location匹配逻辑(翻译自官网)
- Nginx配置文件之location总结
- nginx配置location总结及rewrite规则写法
- nginx location语法使用说明
- nginx配置location总结及rewrite规则写法
- nginx 中配置多个location并解决js/css/jpg/等的加载问题
- Nginx的location配置规则梳理
- Nginx配置中Location的匹配规则
- nginx location alias 和 root 差别
- nginx里location的用法简单说明
- Nginx之location 匹配规则详解
- nginx的location匹配
- Nginx.conf 中的location 详解
- Nginx Location reg
- nginx配置中location的匹配规则