nginx重新整理——————http请求的11个阶段中的find_config[十三]
2023-09-14 08:59:23 时间
前言
简单介绍一下find_config 与 preaccess 阶段。
正文
find_config 很大一部分工作是进行location的匹配。
来一张图看下location指令和merge_slashes:
前缀字符串:
-
常规 比如/http,表示前缀是http,比如 http/aaa 这种。
-
=:精确匹配,表示一定要和这个链接一模一样。
-
^~: 匹配上后则不再进行正则表达式匹配
正则表达式:
~: 大小写敏感的正则匹配
~*: 忽略大小写的正则匹配
合并连续的符号:
merge_slashes
用于内部跳转的命名location:
@ 这种。
下面给一些例子哈:
location的匹配规则:
然后来实验一下例子哈:
location ~ /Test1/$ {
return 200 'first regular expressions match!\n';
}
location ~* /Test1/(\w+)$ {
return 200 'longest regular expressions match!\n';
}
location ^~ /Test1/ {
return 200 'stop regular expressions match!\n';
}
location /Test1/Test2 {
return 200 'longest prefix string match!\n';
}
location /Test1 {
return 200 'prefix string match!\n';
}
location = /Test1 {
return 200 'exact match!\n';
}
实验一:
这里Test1 那么走的是精确匹配。
实验二:
这个是完全匹配,所以选择了3,这里有人就问了,这里~ /Test1/$ 不也是完全匹配吗?因为加了^~ 所以正则表达被拒了。
实验三:
可以看到其实这里面3个都匹配上了,但是因为匹配到了^~ /Test1/,字符最长,且加了^~所以选这个。
实验四:
因为/Test1/Test2完全匹配了,本来应该选择这个的,但是有正则匹配了,所以选正则。
优先级规则:
-
精确匹配
-
匹配字符串最长的,如果匹配字符串最长的没有加~^,那么就会查看正则表达。
-
然后是有多个正则表达,那么选正则表达第一个。
结
下一节介绍preaccess.
相关文章
- FastDFS整合Nginx的模块:fastdfs-nginx-module报错:fdfs_define.h:15:27: 致命错误:common_define.h:没有那个文件或目录
- Nginx编译安装lua-nginx-module
- Nginx配置参数中文详细说明
- Nginx的https配置记录以及http强制跳转到https的方法梳理
- nginx重新整理——————http请求的11个阶段[十二]
- ubuntu21.04(linux):用apt安装nginx/php/mysql/phpmyadmin(开发环境)
- nginx安全:配置allow/deny控制ip访问(ngx_http_access_module)
- 比ngx_http_substitutions_filter_module 更强大的替换模块sregex的replace-filter-nginx-module
- nginx图片过滤处理模块http_image_filter_module安装配置笔记
- 大叔经验分享(77)openresty(nginx+lua)发http请求
- 利用HAProxy取代nginx代理activemq
- nginx重新整理——————http请求的11个阶段[十二]
- nginx重新整理——————http 模块中的请求过程[十一]
- Nginx http_secure_link_module 实现下载防盗链
- k8s使用kubectl命令部署nginx并以nodeport方式暴露端口
- nginx配置文件结构:events http server location块
- nginx ngx_http_core_module 模块中文文档
- 【收藏】Keepalived+Nginx高可用配置(偏nginx配置)
- Atitit 微服务实践 艾提拉著 微服务主要解决几个问题负载均很 目录 1. 微服务的模式 http请求层 vs服务层1 1.1. Http vs 服务层优缺点1 2. 实现技术2
- Nginx配置文件nginx.conf具体解释
- Nginx -- proxy_pass配置
- 005-Nginx 配置文件nginx.conf详解
- nginx无证书代理http/https协议两种解决方案——筑梦之路
- Nginx---Rewrite
- Nginx流量拷贝ngx_http_mirror_module模块使用方法详解