简体   繁体   English

拒绝来自 Nginx 中特定路径的所有 json 文件的请求

[英]Deny request to all json files from particular path in Nginx

Deny request to all json files from particular path in Nginx.拒绝来自 Nginx 中特定路径的所有 json 文件的请求。

We have to block all json files,which is served from /home/assests/js/.我们必须阻止所有来自 /home/assets/js/ 的 json 文件。

location /home/assets/js/mxgraph/package1.json {
    deny all;
}

location /home/assets/js/mxgraph/package2.json {
    deny all;
}

location /home/assets/js/mxgraph/package3.json {
    deny all;
}

location /home/assets/js/mxgraph/package4.json {
    deny all;
}

We are able to block all above json files,but how we can combine these blocks into one,saying block all *.json files need to deny from those path.我们能够阻止所有上述 json 文件,但是我们如何将这些块合并为一个,说阻止所有 *.json 文件需要从这些路径拒绝。

To match all URIs ending with .json you would need to use a regular expression.要匹配所有以.json结尾的 URI,您需要使用正则表达式。

For example:例如:

location ~ ^/home/assets/js/.*\.json$ { deny all; }

Regular expression location statements are evaluated in order until a matching rule is found, so this statement should be placed above any conflicting regular expressions.正则表达式location语句按顺序计算,直到找到匹配的规则,因此该语句应放在任何冲突的正则表达式之上。 See this document for details.有关详细信息,请参阅此文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM