nginx路径匹配
程序员文章站
2022-03-19 18:31:12
...
语法: location [=|~|~*|^~] /uri/ { ... }
- ~* 正则匹配不区分大小写
- ~ 正则匹配区分大小写
- ^~ 路径匹配,匹配后立即终止,不再尝试匹配正则
- = 完全匹配,匹配后立即终止,不再尝试其他任何匹配
优先级:
完全匹配 > 带^~的路径匹配 > 正则(多个正则时优先级按配置顺序) > 路径匹配
官方举例:
location = / { # matches the query / only. [ configuration A ] } location / { # matches any query, since all queries begin with /, but regular # expressions and any longer conventional blocks will be # matched first. [ configuration B ] } location ^~ /images/ { # matches any query beginning with /images/ and halts searching, # so regular expressions will not be checked. [ configuration C ] } location ~* \.(gif|jpg|jpeg)$ { # matches any request ending in gif, jpg, or jpeg. However, all # requests to the /images/ directory will be handled by # Configuration C. [ configuration D ] }
Example requests:
- / -> configuration A
- /documents/document.html -> configuration B
- /images/1.gif -> configuration C
- /documents/1.jpg -> configuration D
上一篇: 2019!抖音淘客到底还能不能做?
推荐阅读
-
nginx下的代理服务器80端口被封的解决方案
-
Linux服务器上安装nginx
-
如何部署vue.js项目nginx
-
Windows下Nginx初入门 windows10 下载 windows优化大师 windows7 64位旗舰
-
Nginx虚拟目录配置文件(包含PHP配置与重写)
-
最简单实现跨域的方法:使用nginx反向代理
-
thinkpad win7 oem 让Nginx支持ThinkPHP的URL重写和PATHINFO的方法分享
-
linux服务器之LVS、Nginx和HAProxy负载均衡器对比总结
-
nginx - php file not found
-
Nginx下10个安全问题提示,nginx10安全问题