nginx location的配置
来源:互联网 发布:万科金域名城怎么样 编辑:程序博客网 时间:2024/05/22 10:25
基本原则:
- 首先匹配确定的前缀,采用最长匹配原则,记下最长匹配的前缀
- 如果最长匹配前缀带有* ^~*, 则直接使用最长匹配前缀,不会进行正则表达式匹配,否则继续第3步。
- 在匹配正则表达式,按照正则表达式出现的顺序进行匹配
- 一旦找到一个匹配的正则表达式,则正则表达式搜索停止,并且使用该表达式
- 如果找不到则使用最长匹配前缀
符号规则:
- = 表示完全匹配,如果匹配到则停止搜索
- ~ 后接大小写敏感的正则表达式
- ~* 后面接大小写不敏感的正则表达式
- @ 前缀定义的路径并不是用来处理常规请求,而是用于重定向,不能有嵌套
例子
现有以下location配置:
location = / { [configuration A]}location / { [configuration B]}location /documents/ { [configuration C]}location ^~ /images/ { [configuration D]}location ~* \.(gif|jpg|jpeg)$ { [configuration E]}
有以下几个请求:
a. “/”
b. “/index.html”
c. “/documents/1.jpg”
d. “/images/1.gif”
e. “/documents/document.html”
匹配结果如下:
a 按照=规则, 配置 A 满足匹配条件,于是匹配A,停止搜索
b 最长匹配前缀为 “/” , 找不到满足匹配的正则表达式,所以使用最长匹配前缀, 匹配 B , 不匹配A的原因是 = 是要求完全匹配的,不满足条件
c 最长匹配前缀为”/documents/”,但可以找到匹配的正则表达式 E, 故最终匹配为E
d 最长匹配前缀为”/images/”, 由于 D 有前缀 “^~”,按照上面写的基本规则2,表示直接使用最长匹配前缀,所以这里匹配D
e 最长匹配前缀为”/documents/” , 找不到符合的正则表达式, 所以匹配C
参考:
https://nginx.org/en/docs/http/ngx_http_core_module.html#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和rewrite配置语法
- Nginx 的 Location 配置指令块
- nginx 代理服务器location的配置规则
- nginx配置中location的语法
- Java日期格式转化工具(date格式转为string格式,string转date,string转timestamp类型)
- 感冒药
- redis -window
- MyBatis 延迟加载,一级缓存,二级缓存设置
- 一个简单的js快速排序算法
- nginx location的配置
- C++学习笔记十四之引用变量&
- GitHub desktop windows 创建、添加、上传 基础教程
- CodeForces
- RxSwift 系列(九) -- 那些难以理解的概念
- 【云和恩墨】性能优化:Linux环境下合理配置大内存页(HugePage)
- spring in action 面向切面
- 数组遍历排序
- NDK的基础教程 四 动态注册