Script for blocking ip address from specific countries on nginx
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Setting the countries to block

You must set the $ISO var with the ISO code of the countries you want to deny. You can add multiple countries with space separator: ISO="ng ru"

Setting your server paths

You must change the next vars if they are not right in your server:


Modifying your nginx configuration file

Open your nginx configuration file vi /etc/nginx/nginx.conf

Add the next into the http section: include /etc/nginx/blockips.conf;

Be careful with your server paths. It is important your included file is the same as the OUTPUTFILE configuration var.

(Optional) Create a cronjob

In order to keep update the ip list, you should create a cronjob to refresh the list every day. 0 1 * * * /path/to/