Country Blocking with nginx GeoIP on Ubuntu/Debian

On Ubuntu/Debian, install nginx geoip module with

Now edit nginx.conf

Find

Add below

nginx geoip

You can add 2 letter country code and set ye/no as required.

To implement GeoIP blocking for a web site, you need to edit server entry for the web site. In this cause, i will use the default web site.

Find

Add blow

nginx geoip server configuration

This will block access to the web site from any country that is not listed in nginx.conf

You need to restart nginx web server

If you need to redirect blocked users to another site, use

This will redirect the visitor to google if their country is not US, AU or CA.

See Nginx

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *