Version 1.0
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!
If you have installed the standard Debian Etch lighttpd package, you should use this way to build and install a new lighttpd .deb package including mod_geoip.
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:
cd lighttpd-1.4.13/src/
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:
cd ../
aclocal && automake -a && autoconf
dpkg-buildpackage
(At the end of the build process, you'll most likely see the following warnings which you can ignore:
dpkg-genchanges
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)
server1:/usr/src/lighttpd-1.4.13#
)
Now go to the /usr/src directory and check its content:
As you see, we now have new lighttpd .deb packages in that directory. Install the new lighttpd with mod_geoip as follows:
dpkg -i lighttpd_1.4.13-4etch8_i386.deb
Now we must configure lighttpd to use mod_geoip. First, we download the GeoIP country database:
mkdir /usr/local/data
cd /usr/local/data
wget http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
gunzip GeoIP.dat.gz
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:
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):
vi /var/www/geoiptest.php
<?php
print_r($_SERVER);
?>
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.
Recent comments
20 hours 11 min ago
22 hours 20 min ago
1 day 11 hours ago
2 days 2 hours ago
2 days 8 hours ago
2 days 13 hours ago
2 days 16 hours ago
3 days 7 hours ago
3 days 9 hours ago
3 days 11 hours ago