nginx location详解
来源:互联网 发布:手机版windows系统 编辑:程序博客网 时间:2024/05/17 02:50
location 有”定位”的意思, 根据Uri来进行不同的定位.在虚拟主机的配置中,是必不可少的,location可以把网站的不同部分,定位到不同的处理方式上.
location 的语法location [=|~|~*|^~] patt {# 精确匹配: 相等(=)# 字符串匹配: 字符串匹配(空格) 匹配开头(^~)# 正则匹配: 区分大小写匹配(~) 不区分大小写匹配(~*) 区分大小写不匹配(!~) 不区分大小写不匹配(!~*)}
大概分为3类
location = patt {} [精准匹配]location patt{} [一般匹配]location ~ patt{} [正则匹配]
location匹配优先级
精确匹配 > 字符串匹配( 长 > 短 [ 注: ^~ 匹配则停止匹配 ]) > 正则匹配( 上 > 下 )# 精确匹配只能命中一个# 字符串匹配使用匹配最长的最为匹配结果# 正则匹配按照location定义的顺序进行匹配,先定义具有高优先级
如果有精确匹配,则命中精确匹配,如果没有精确匹配字符串匹配优先搜索,但是只是记录下最长的匹配 ( 如果 ^~ 是最长的匹配,则会直接命中,停止搜索正则 ),然后继续搜索正则匹配,如果有正则匹配,则命中正则匹配,如果没有正则匹配,则命中最长的字符串匹配.
实例
location = /html/index.html{ echo 'config1';}location /html/index.html { echo 'config2';}location \/html\/index\.html$ { echo 'config3';}location /index.html { echo 'config4';}
如果请求http://xxx/html/index.html,那么有精确匹配则匹配,所以config1被匹配中
如果删除config1,重新加载配置文件再次请求,则config3被匹配中
如果删除config1,config3,重新加载配置文件再次请求,则config2被匹配中,因为config2比config4匹配更长
0 0
- Nginx之location详解
- nginx location配置详解
- nginx location优先级详解
- nginx location配置详解
- nginx location 模块详解
- nginx location详解
- nginx 之 location 详解
- nginx location详解
- nginx配置文件中的location详解
- nginx配置文件中的location详解
- nginx配置文件中的location详解
- Nginx配置中的location详解
- Nginx.conf 中的location 详解
- 【Nginx】location 匹配规则详解
- nginx的location配置详解
- nginx的location配置详解
- nginx的location配置详解
- Nginx.conf 中的location 详解
- Opencontrail 流的处理
- ESP8266最小系统板以及下载方式
- linux grep命令详解
- 图像处理之插值运算
- 碰到的一些面试问题
- nginx location详解
- 去掉.net页面中的input type=hidden name=__VIEWSTATE id=__VIEWSTATE
- 图片上传 显示缩略图
- Servlet+jsp 验证码
- sizeof计算对象所占内存大小详解
- Linux Socket编程(不限Linux)
- Linux多线程编程(不限Linux)
- Machine Learning in Python
- Discuz!帖子刷新后阅读数增加随机值的方法