How to Use Mod_GeoIP on your Apache Server

As server traffic becomes increasingly globalized, it’s important to show content in the right languages and delivery channels based upon the originating IP of the user. Implementing the modular on your Apache server will give your development team the ability to show different content to users according to their IP address, and can help localize global brands on the web.

To start, you’ll need to install the GeoIP C Library on your apache server. There are a variety of creative uses for the module, which allows users to serve targeted content. The library includes an install file which makes the process relatively straightforward. Follow the basic steps to install the module:

Create a new directory on your server with the following commands

mkdir /home/admin/geoip
cd /home/admin/geoip
mkdir mod_geoip
cd mod_geoip

Install the library on your Apache server

tar xzfv GeoIP.tar.gz
cd GeoIP*
./configure
make
make check
make install

Install the module on your server

tar xzfv mod_geoip.tar.gz
cd mod_geoip
apxs -cia -I/usr/local/include -L/usr/local/lib -lGeoIP mod_geoip.c

Update your /etc/ld.so.conf file by adding

/usr/kerberos/lib
/usr/lib/mysql
/usr/X11R6/lib
/usr/local/lib

Add lines to your Add Module section of your http.conf file

LoadModule geoip_module /usr/lib/apache/mod_geoip.so
GeoIPEnable On

After that you can restart Apache to start implementing some of the features of the module such as updating your configuration files to show different content pages according to IP address. A common use of the module is to group countries according to language so users from Mexico and Spain, for example, see your Spanish site while US users see an English site:

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

# Redirect US Traffic to your English page

RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://us.yourcompany.com$1 [L]

# Redirect Spanish countries to the ES Page

RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(ES|MX)$
RewriteRule ^(.*)$ http://es.yourcompany.com$1 [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(ES|MX)$
RewriteRule ^(.*)$ http://es.yourcompany.com$1 [L]

0 responses so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment




 

Search Website

 
 
 

Top 10 Hosting Companies

MyHosting - $4.00 USD
InMotion Hosting - $5.95 USD
WebHostingHub - $4.95 USD
JustHost - $3.95 CDN
iPage - $3.50 CDN
HostGator - $4.95 USD
FatCow - $3.67 USD
GreenGeeks - $4.95 USD
BlueHost - $6.95 USD
10 GoDaddy - $4.11 CDN