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/
You may also want to read these posts:
- Nginx As Reverse Proxy IPV6 to IPV4 Website
- Show GeoIP Badge On Your Website Using PHP And JavaScript
- Nginx Limit Available Methods
- Build Nginx RPM With ngx_cache_purge module
- Nginx Configuration SyntaxHighlighting
- Nginx – Customizing 404 page
- Nginx enabling TLS SNI support on centos 5
- Nginx IPV6
- Nginx Blocking Spoofed Google Bot
- Nginx, Strip All Newlines Using nginx-nonewlines Module
Follow me on Twitter
Wow, akhirnya ketemu juga cara jalanin GeoIP di nginx setelah 5 bulan cari2.
Makasih banget bro
sama sama