Sep 162010
 

First grab this perl script which you will use to convert Maxmind’s geo IP database into a format usable by Nginx.

make it executable

$ chmod 755 geo2nginx.pl

Then download Maxmind’s latest GeoLite country database in CSV format.

Unzip it, and run perl script

$ unzip GeoIPCountryCSV.zip
$ ./geo2nginx.pl < GeoIPCountryWhois.csv > nginxGeo.txt

Copy nginxGeo.txt into your nginx config directory.

Then add the following text in the ‘http’ section of your nginx.conf file:

geo $country {
	default no;
	include nginxGeo.txt;
}

Then add the following in the ’server’ section of your nginx.conf file:

if ($country ~ ^(?:US|CA|ES)$ ){
	set $limit_rate 10k;
}
if ($country ~ ^(?:BR|ZA)$ ){
	set $limit_rate 20k;
}

This limits anyone from the USA, Canada and Spain to a maximum of 10 kilobits per second of bandwidth. It gives anyone from Brazil and South Africa 20 Kbps of bandwidth. Every other country gets the maximum.

source: http://markmaunder.com/2010/how-to-limit-website-visitor-bandwidth-by-country/

  2 Responses to “Nginx, limit website visitor bandwidth by country”

Comments (2)
  1. Wow, akhirnya ketemu juga cara jalanin GeoIP di nginx setelah 5 bulan cari2.
    Makasih banget bro

  2. sama sama 🙂

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.