JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Nginx学习笔记(06) location的匹配规则

wys521 2024-09-27 13:42:14 精选教程 20 ℃ 0 评论

语法结构

语法: location [=|~|~*|^~] uri {...}
上下文: server location

匹配规则&优先级

1. =
   含义: 精确匹配
   优先级: 1
   示例: location = /images/ {...}
   最佳匹配: /images/
                            
2. ^~
   含义: 匹配到即停止搜索(屏蔽'?'}
   优先级: 2
   示例: location ^~ /images/ {...}
   最佳匹配: /images/1.jpg
3. ~
   含义: 正则匹配,区分大小写
   优先级: 3
   示例: location ~ .(jpg|gif)$ {...}
   最佳匹配: /img/1.jpg
4. ~*
   含义: 正则匹配,不区分大小写
   优先级: 4
   示例: location ~* .(jpg|gif)$ {...}
   最佳匹配: /img/1.JPG
5. 无符号
	 优先级: 5
   示例: location / {...}
   最佳匹配: /images/1.html
   

当配置中出现多个location时按照优先级顺序逐一匹配

深入理解location中URL结尾的反斜线


-- 默认或将test作为目录处理,匹配root指定路径下的test目录的index.html,
-- 如果test目录不存在,则匹配root指定路径下的test文件,
-- 另外如果按照目录匹配原则,访问时会发生重定向 localhost/test => localhost/test/
location /test {...}

-- 仅将test看作目录处理,匹配root指定路径下的test目录的index.html
location /test/ {...}

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表