简体   繁体   中英

Deny request to all json files from particular path in Nginx

Deny request to all json files from particular path in Nginx.

We have to block all json files,which is served from /home/assests/js/.

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.

To match all URIs ending with .json you would need to use a regular expression.

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. See this document for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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