具有否定模式的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$ { }更多推荐
发布评论