Block website access by country with Nginx

August 19th, 2015 by
Add the following to the http block in the nginx.conf file
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allow_visit {
    default no;
    US yes;
    JP yes;	
    CA yes;
}

Add the following inside your server block
if ($allow_visit = no) {
    		return 500;
	}

Post a Comment

You must be logged in to post a comment.