Geolocalisation avec Apache 2
This guide explains how to set up mod_geoip with Apache2 on a Debian Etch system. mod_geoip looks up the IP address of the client end user. This allows you to redirect or block users based on their country. You can also use this technology for your OpenX (formerly known as OpenAds or phpAdsNew) ad server to allow geo targeting.
2 Installing mod_geoip
To install mod_geoip, we simply run:
apt-get install libapache2-mod-geoip
Then we open /etc/apache2/mods-available/geoip.conf and uncomment the GeoIPDBFile line so that the file looks as follows:
<IfModule mod_geoip.c> GeoIPEnable On GeoIPDBFile /usr/share/GeoIP/GeoIP.dat </IfModule>
Next we restart Apache:
That's it already!
3 A Short Test
To see if mod_geoip is working correctly, we can create a small PHP file in one of our web spaces (e.g. /var/www):
<html> <body> <?php $country_name = apache_note("GEOIP_COUNTRY_NAME"); print "Country: " . $country_name; ?> </body> </html>
Call that file in a browser, and it should display your country (make sure that you're calling the file from a public IP address, not a local one).
4 Use Cases
You can use mod_geoip to redirect or block/allow users based on their country.
You can also use mod_geoip with OpenX/OpenAds/phpAdsNew.