Skip to content

JerVoo/nginx-block-bots

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Block unwanted visitors through nginx

Every website has it's own share of unwanted visitors. Crawlers, spam bots, DDoS-attacks... everything may happen.

Using this configuration, you can block unwanted visitors from your website. Most types of crawlers are being blocked.

How it works

Insert the file block.conf into your nginx configuration directory and include it in your nginx using the following configuration:

http {
    ...
    include block.conf;
    ...
}

This will include the variables into your configuration.

And now let's get to the blocking

After you've included the block.conf file into your nginx configuration, you can start blocking the bots from your server-blocks.

server {
	...
	location / {
	    # A bad bot has been found, return a 403 error and don't show them in logs
	    if ($limit_bots = 1) {
	        access_log off;
		    return 403;
	    }

	    # Bad referer has been found. Throw 403 error to deny access for the user and don't log them
	    if ($bad_referer = 1) {
	        access_log off;
		    return 403;
	    }

	    # Only allow GET, HEAD and POST requests. If another request is thrown,
	    # throw a 444 error (No Reponse) to close the connection
	    if ($request_method !~ ^(GET|HEAD|POST)$) {
	        return 444;
	    }
	}
}

Thanks to

mariusv

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published