Blocking URLs in batch using nginx map

Blocking multiple suspicious URL requests in nginx using map directive

To return 444 HTTP code, for large amount of URLs you will need to add configuration below.

1
2
3
4
map $request_uri $block_request {
      default 0;
      include /etc/nginx/map/blockedrequests.map; # location to the file
}

content of blockedrequests.map should look like that

1
2
3
4
5
/site.tar.gz  1;
/site.tgz  1;
/site.zip  1;
/sql.sql  1;
/sql.txt  1;

and then you need to add snippet below within the server block to actually do the blocking

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
server {

...
    # Block any requests from blockedrequests.map
    if ($block_request) {
       return 444;
    }
...

}