Nginx的location匹配问题
来源:互联网 发布:淘宝上的自行车怎么样 编辑:程序博客网 时间:2024/04/26 01:26
Location语法语法:location [=|~|~*|^~] /uri/ { … }
= –> 开头表示精确匹配
^~ –> 开头表示uri以某个常规字符串开头,理解为匹配url路径即可。
nginx不对url做编码,因此请求为/static/20%/aa,可以被规则^~ /static/ /aa匹配到(注意是空格)。
~ –> 开头表示区分大小写的正则匹配
~* –> 开头表示不区分大小写的正则匹配
!~和!~* –> 分别为区分大小写不匹配及不区分大小写不匹配的正则
/ –> 通用匹配,任何请求都会匹配到。
多个location配置的情况下匹配顺序为:
首先匹配=,其次匹配^~, 其次是按文件中顺序的正则匹配,最后是交给 / 通用匹配。当有匹配成功时候,停止匹配,按当前匹配规则处理请求。
#直接匹配网站根,通过域名访问网站首页比较频繁,使用这个会加速处理,官网如是说。#这里是直接转发给后端应用服务器了,也可以是一个静态首页# 第一个必选规则location = / { proxy_pass http://tomcat:8080/index}# 第二个必选规则是处理静态文件请求,这是nginx作为http服务器的强项# 有两种配置模式,目录匹配或后缀匹配,任选其一或搭配使用location ^~ /static/ { root /webroot/static/;}location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ { root /webroot/res/;}#第三个规则就是通用规则,用来转发动态请求到后端应用服务器#非静态文件请求就默认是动态请求,自己根据实际把握#毕竟目前的一些框架的流行,带.php,.jsp后缀的情况很少了location / { proxy_pass http://tomcat:8080/}
http://www.cnblogs.com/lidabo/p/4169396.html
匹配优先级:
location /exact/match.html 高于 location ^~高于location ~高于location /
具有多个location ~时按编辑顺序匹配
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 location匹配规则
- nginx location匹配规则
- NGINX location 匹配规则
- nginx location匹配规则
- nginx location匹配规则
- nginx location匹配规则
- 策略模式
- NoSQL_MongoDB_MongoDB的写安全机制
- linux压缩解压
- 智能小车的制作(五)
- 绿色instance client连接Oracle服务器的配置方法
- Nginx的location匹配问题
- Android View绘制原理的初步理解
- android studio 如何将工程提交到github
- 深入理解Java虚拟机
- leetcode(2) - Add Two Numbers
- 谢娜终于透露了至今未生孩子的原因,网友直呼接受不了
- 国庆过后老革命
- Java中对象锁和类锁举例
- 浅谈《家》中觉新形象与封建宗法制