nginx 的location的匹配顺序
匹配规则

匹配顺序

示例
[root@python vhast]# cat test.conf
server {
server_name haha.com;
#listen 8080;
rewrite_log on;
error_page 404 /403.html;
#return 405;
location /{
#return 404 "find nothing!\n";
}
root html/;
location /first {
rewrite /first(.*) /second$1 last;
return 200 1first!\n';
}
location /second {
#rewrite /second(.*) /third$1 break;
rewrite /second(.*) /third$1 last;
return 200 'second!\n';
}
location /third {
return 200 'third!\n';
}
location /redirect1 {
rewrite /redirect1(.*) $1 permanent;
}
location /redirect2 {
rewrite /redirect2(.*) $1 redirect;
}
location /redirect3 {
rewrite /redirect3(.*) http://haha.com:$1;
}
location /redirect4 {
rewrite /redirect4(.*) http://haha.com:$1 permanent;
}
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';
}
}
测试
[root@python vhast]# curl http://haha.com/Test1
exact match!
[root@python vhast]# curl http://haha.com/Test1/
stop regular expressions match!
[root@python vhast]# curl http://haha.com/Test1/Test2
longest regular expressions match!
[root@python vhast]# curl http://haha.com/Test1/Test2/
longest prefix string match!
[root@python vhast]# curl http://haha.com/test1/Test2 #没有匹的话会记住匹配最长的那个
longest regular expressions match!
nginx 的location的匹配顺序的更多相关文章
- Nginx 中 location 的匹配顺序
nginx中location的匹配模式有以下几种: 精确匹配:以=开头,只有完全匹配才能生效,例子location = /uri 非正则匹配:以^~开头,^表示非.~表示正则,例子location ^ ...
- Nginx中的一些匹配顺序
Nginx中经常需要做各种配置,总结如下: 1.server_name配置 nginx中的server_name指令主要用于配置基于名称虚拟主机,同一个Nginx虚拟主机中,可以绑定多个server_ ...
- nginx之location的匹配规则
nginx之location的匹配规则 一.语法规则 location [=|~|~*|^~] /uri/ { - } 符号 含义 = 开头表示精确匹配 ^~ 开头表示 uri 以某个常规字符串开头 ...
- Nginx 关于 location 的匹配规则详解
有些童鞋的误区 1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通, ...
- Nginx location指令匹配顺序规则
location匹配命令 1. “= ”,字面精确匹配, 如果匹配,则跳出匹配过程.(不再进行正则匹配) 2. “^~ ”,最大前缀匹配,如果匹配,则跳出匹配过程.(不再进行正则匹配) 3. 不带任何 ...
- nginx中server的匹配顺序
在开始处理一个http请求时,nginx会取出header头中的host,与nginx.conf中每个server的server_name进行匹配,以此决定到底由哪一个server块来处理这个请求. ...
- nginx之location简单匹配总结
location匹配规则与优先级 = 精确匹配,匹配成功则停止匹配 ^~ 前缀普通字符匹配,匹配成功则停止匹配 ~ 正则匹配,区分大小写:多个正则按顺序匹配 ~* 正则匹配,不区分大小写:多个 ...
- Nginx location 匹配顺序整理
Nginx location模块整理 具体的Nginx安装就不在这里描述了,这里只是为了对location的描述 Nginx环境 a. 查看当前系统cat /etc/redhat-release [r ...
- Nginx之location 匹配规则详解
有些童鞋的误区 1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通, ...
随机推荐
- 删除数据高级用法:delete,truncate
1.语法: delete 允许使用条件(删除符合条件的数据) 允许使用limit,限制删除的记录数.limit N 常见的是,limit配合order by来使用:先将结果排序,再删除固定数量 ...
- 解决:执行python脚本,提示错误:/usr/bin/python^M: 解释器错误: 没有那个文件或目录。
执行python脚本,提示错误: /usr/bin/python^M: 解释器错误: 没有那个文件或目录. 产生错误原因: \r字符被显示为^M,这时候只需要删除这个字符就可以了. Linux环境下: ...
- unittest 测试套件使用汇总篇
# coding=utf-8import unittestfrom inspect import isfunction def usage(): """also unit ...
- 避坑之Hadoop安装伪分布式(Hadoop3.2.0/Ubuntu14.04 64位)
一.安装JDK环境(这个可以网上随意搜一篇教程了照着弄,这里不赘述) 安装成功之后 输入 输入:java -version 显示如下说明jdk安装成功(我这里是安装JDK8) 二.安装Hadoop3. ...
- java 面试题 mybatis 篇
1. 一级缓存和二级缓存? 一级缓存策略: 二级缓存策略: 2. 缓存回收策略 LRU – 最近最少使用的:移除最长时间不被使用的对象. FIFO – 先进先出:按对象进入缓存的顺序来移除它们. ...
- MySQL基本查询
1.查询某数据库中表的总数 select count(*) from information_schema.tables where table_schema='dbname'; 2.仅占一列显示某数 ...
- 03-Docker-Engine详解
目录 03-Docker-Engine详解 摆脱 LXC 摒弃大而全的 Docker daemon 开放容器计划(OCI)的影响 runc containerd 启动一个新的容器 该模型的显著优势 s ...
- spring security 方法权限使用
前面我们讲过了使用<security:intercept-url>配置url的权限访问,下面我们讲解一下基于方法的权限使用默认情况下, Spring Security 并不启用方法级的安全 ...
- 4_4 信息解码(UVa213)<二进制:输入技巧与调试技巧>
消息编码方案要求在两个部分中发送一个被编码的消息.第一部分:称为头,包含消息的字符.第二部分包含一个模式 表示信息.你必须写一个程序,可以解码这个消息. 你的程序的编码方案的核心是一个序列的“0和1” ...
- 用纯css实现双边框效果
1. box-shadow:0 0 0 1px #feaa9e,0 0 0 5px #fd696f 2. border:1px solid #feaa9e; outline:5px solid #fd ...