Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 05/26/2008
This guide explains how to set up mod_geoip with lighttpd on a Fedora 9 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.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
I'm assuming that you have a running Fedora 9 system with a working lighttpd and PHP.
2 Installing mod_geoip
To install mod_geoip for lighttpd, we simply run:
yum install lighttpd-mod_geoip
Then open /etc/lighttpd/lighttpd.conf and add "mod_geoip", to the server.modules section; also add the geoip.db-filename and geoip.memory-cache directives below the server.modules section:
You will find the GeoIP database (GeoIP.dat) in the /usr/share/GeoIP directory. As the geographic allocation of IP addresses can change over time, it's a good idea to download the newest GeoIP.dat now:
mv GeoIP.dat GeoIP.dat_orig
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/lighttpd) (of course, PHP must be enabled in your lighttpd installation):
Call that file in a browser, and it should display the SERVER array including values for GEOIP_COUNTRY_CODE, GEOIP_COUNTRY_CODE3, and GEOIP_COUNTRY_NAME(make sure that you're calling the file from a public IP address, not a local one).
If you want to use lighttpd + mod_geoip for your OpenX ad server, make sure you select MaxMind mod_apache GeoIP under Settings > Main Settings > Geotargeting Settings. This will work for lighttod + mod_geoip as well.