Location 字符匹配详解

1.Location后什么都不带直接指定目录

root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "/null-1"; } } \[root@Nginx conf.d\]# curl lee.timinglee.org/null/ /null-1 \[root@Nginx conf.d\]# curl lee.timinglee.org/NULL/ \ \\404 Not Found\\ \ \\404 Not Found\\ \\nginx/1.28.1\ \ \

2.location 后用 =

root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { #精确匹配到此结束 return 200 "null-2"; } location \~ /null { return 200 "null-3"; } } \[root@Nginx conf.d\]# nginx -s reload \[root@Nginx conf.d\]# curl lee.timinglee.org/null null-2

root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { return 200 "null-2"; } location \~ /null { return 200 "null-3"; } location \^\~ /lee { return 200 "lee"; } } \[root@Nginx conf.d\]# nginx -s reload lee \[root@Nginx conf.d\]# curl lee.timinglee.org/lee lee \[root@Nginx conf.d\]# curl lee.timinglee.org/test/lee \ \\404 Not Found\\ \ \\404 Not Found\\ \\nginx/1.28.1\ \ \ \[root@Nginx conf.d\]# curl lee.timinglee.org/leeab/test lee

root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { return 200 "null-2"; } location \~ /null { return 200 "null-3"; } location \^\~ /lee { return 200 "lee"; } location \~ /timing/ { return 200 "timing"; } } \[root@Nginx conf.d\]# nginx -s reload \[root@Nginx conf.d\]# curl lee.timinglee.org/timinga/ timing \[root@Nginx conf.d\]# curl lee.timinglee.org/timing/ timing \[root@Nginx conf.d\]# curl lee.timinglee.org/a/timing/ timing \[root@Nginx conf.d\]# curl lee.timinglee.org/a/timinga/ timing \[root@Nginx conf.d\]# curl lee.timinglee.org/a/atiming/ \ \\404 Not Found\\ \ \\404 Not Found\\ \\nginx/1.28.1\ \ \

5.location 后用"~*"

root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { return 200 "null-2"; } location \~ /null { return 200 "null-3"; } location \^\~ /lee { return 200 "lee"; } location \~ /timing/ { return 200 "timing"; } location \~\* /timinglee { return 200 "timinglee"; } } \[root@Nginx conf.d\]# nginx -s reload \[root@Nginx conf.d\]# curl lee.timinglee.org/Timinglee/ timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/timinglee/ timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/timinglee/a timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/a/timinglee/a timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/a/atiminglee/a \ \\404 Not Found\\ \ \\404 Not Found\\ \\nginx/1.28.1\ \ \ \[root@Nginx conf.d\]# curl lee.timinglee.org/a/timingleea/a timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/a/Timinglee/a timinglee

6.location 后用"\"

root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { return 200 "null-2"; } location \~ /null { return 200 "null-3"; } location \^\~ /lee { return 200 "lee"; } location \~ /timing/ { return 200 "timing"; } location \~\* /timinglee { return 200 "timinglee"; } location \~\* \\.(img\|php\|jsp)$ { return 200 "app"; } } \[root@Nginx conf.d\]# nginx -s reload \[root@Nginx conf.d\]# curl lee.timinglee.org/test.php app \[root@Nginx conf.d\]# curl lee.timinglee.org/test.jsp app

相关推荐
一个在高校打杂的1 分钟前
honeypot之opencanary(轻量化蜜罐)
linux·网络安全·网络攻击模型·安全威胁分析·策略模式
大明者省3 分钟前
Ubuntu22.04 宝塔面板与 XFCE 远程桌面端口兼容性分析
运维·服务器·数据库·笔记
@菜菜_达6 分钟前
jquery.inputmask插件介绍
前端·javascript·jquery
QuZhengRong6 分钟前
【Luck-Report】缓存
java·前端·后端·vue·excel
s_w.h8 分钟前
【 linux 】认识make和makefile
linux·运维·bash
jiayong2311 分钟前
前端面试题库 - 浏览器与网络篇
前端·网络·面试
Csvn15 分钟前
小程序开发:微信小程序与 uni-app 实战指南
前端
不怕犯错,就怕不做19 分钟前
ARM设备异常断电容易造成数据损坏,硬件如何设计
linux·驱动开发·嵌入式硬件
摸鱼小李上线了21 分钟前
vue项目页面添加水印实现方法
前端·javascript·vue.js
Harm灬小海24 分钟前
【云计算学习之路】学习Centos7系统-Linux软件包管理
linux·运维·服务器·学习·云计算·yum·rpm