Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 05/11/2008
This guide explains how to set up mod_geoip with lighttpd 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. I will show two ways to build mod_geoip - the first way is to build a new lighttpd .deb package (including mod_geoip) which is the way I recommend. This works only if you have installed the standard Debian Etch lighttpd package. If you've compiled lighttpd yourself, then the second way is for you: it shows how to build mod_geoip.so for your lighttpd version.
I do not issue any guarantee that this will work for you!
As you see, we now have the sources of lighttpd 1.4.13 (from which the standard lighttpd package for Debian Etch was built).
Let's go on:
wget -O mod_geoip.c http://trac.lighttpd.net/trac/attachment/wiki/Docs/ModGeoip/mod_geoip.5.c?format=raw
http://trac.lighttpd.net/trac/attachment/wiki/Docs/ModGeoip/mod_geoip.5.c?format=raw is for lighttpd 1.4.x. For lighttpd 1.5.x, you'd have to download http://trac.lighttpd.net/trac/attachment/wiki/Docs/ModGeoip/mod_geoip.4.c?format=raw instead.
Now open Makefile.am and after the last lib_LTLIBRARIES stanza (should be the lib_LTLIBRARIES += mod_accesslog.la stanza), add the following stanza:
That's it. Now we can build the new lighttpd .deb package:
aclocal && automake -a && autoconf
(At the end of the build process, you'll most likely see the following warnings which you can ignore:
dpkg-genchanges: not including original source code in upload
dpkg-buildpackage: binary and diff upload (original source NOT included)
(WARNING: Failed to sign .dsc and .changes file)
Now go to the /usr/src directory and check its content:
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) (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.