Skip to content

Nginx Block URLs

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.

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

/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

server {

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

}