具有否定模式的nginx位置(nginx location with negation pattern)

编程入门 行业动态 更新时间:2024-10-24 16:30:28
具有否定模式的nginx位置(nginx location with negation pattern)

如何将否定模式添加到位置块?

我想匹配所有名为*.js文件,但不匹配名为*-php.js文件

此模式将匹配所有*.js文件,包括*-php.js

location ~ \.js$ { }

How to add a negation pattern to a location block?

I want to match all files named *.js but not files named *-php.js

This pattern will match all *.js files including *-php.js

location ~ \.js$ { }

最满意答案

从文档 :

正则表达式按其外观顺序进行检查

所以你可以简单地把你的“否定模式”放在:

location ~ -php\.js$ { deny all; } location ~ \.js$ { }

From the doc:

regular expressions are checked, in the order of their appearance

So you may simply put your "negation pattern" before:

location ~ -php\.js$ { deny all; } location ~ \.js$ { }

更多推荐

本文发布于:2023-04-29 10:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   模式   nginx   pattern   location

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!