首页域名资讯 正文

nginx location 取反

2024-09-04 5 0条评论

有这么个需求,只允许html、shtml、js、css访问,其它任何文件都不允许访问。

在nginx location配置取反,如下:

1 2 3 4 location ~ * . * \ . ( ? ! [ html | shtml | js | css ] $ ) {          return 503 ; }

nginx的正则使用PCRE(Perl Compatible Regular Expressions)。

Extension Description
(?# TEXT) This extension lets you add comments to your regular expression. The TEXT value is ignored.
(?:…) This extension lets you add parentheses to your regular expression without causing a pattern memory position to be used.
(?=…) This extension lets you match values without including them in the $& variable.
(?!…) This extension lets you specify what should not follow your pattern. For instance, /blue(?!bird)/ means that "bluebox" and "bluesy" will be matched but not "bluebird".
(?sxi) This extension lets you specify an embedded option in the pattern rather than adding it after the last delimiter. This is useful if you are storing patterns in variables and using variable interpolation to do the matching.

文章转载来自:trustauth.cn

文章版权及转载声明

本文作者:亿网 网址:https://www.edns.com/ask/post/150640.html 发布于 2024-09-04
文章转载或复制请以超链接形式并注明出处。