Git Product home page Git Product logo

nginx-block-bots's Introduction

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

nginx-block-bots's People

Contributors

harveychow avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.