匹配规则

匹配顺序

示例

[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!

  

最新文章

  1. AngularJS 脏检查深入分析
  2. mysql-5.7.16 解压版安装
  3. gulp学习笔记4
  4. ios面试总结-
  5. ES 基础
  6. SGU 119.Magic pairs
  7. 一些tcp通讯代码
  8. Python打包工具setuptools的使用
  9. Java:基于MD5的文件监听程序
  10. P1282 多米诺骨牌 (背包变形问题)
  11. javascript 插入DOM节点
  12. 安全需求-建模归类——By Me
  13. ASP.NET重写Render 加载CSS样式文件和JS文件(切换CSS换皮肤)
  14. JAVA中String.format的用法 转16进制,还可以补0
  15. [转]你所不知的 CSS ::before 和 ::after 伪元素用法
  16. 六、物理数据模型(PDM逆向工程)
  17. Linux就业技术指导(二):简历项目经验示例
  18. 关于gcc编译器中函数不用进行原型声明的解释
  19. hdu 3792 Twin Prime Conjecture 前缀和+欧拉打表
  20. 课程设计——利用信号量实现生产者-消费者问题(java)

热门文章

  1. java基础(温故而知新)
  2. concat merge
  3. base64加/解密算法C++实现
  4. pwnable.kr-balckjack-Writeup
  5. 启动MySQL5.7时报错:initialize specified but the data directory has files in it. Aborting.
  6. oracle 唯独测试视图
  7. 【代码学习】PYTHON 进程
  8. SDNU_ACM_ICPC_2020_Winter_Practice_1st
  9. netty(一)---服务端源码阅读
  10. Python os模块、os.path模块常用方法