kieranbarnes Independent PHP, WordPress & CubeCart Programmer

mod_geoip Revisted including stopping spam in phpBB 2

Posted on February 15, 2010

I've recently moved a client's forum onto a new cPanel server, previously it was on a home-brew Ubuntu server.
So I had to install mod_geoip onto cPanel in CentOS. It wasn't as bad as I was expecting.

First off, we need to download the GeoIP libraries.Installing the library

  1. wget http://www.maxmind.com/download/geoip/api/.../c/GeoIP.tar.gz
  2. tar xzfv GeoIP.tar.gz
  3. cd GeoIP-1.4.6/
  4. ./configure
  5. make
  6. make check
  7. make install

Download data file

The GeoIP system works by reading a binary data file, we need to download it. Its a good idea to write a cron wrapper around this to keep it updated

  1. mkdir /usr/share/GeoIP/
  2. cd /usr/share/GeoIP/
  3. mv GeoIP.dat GeoIP.dat_orig
  4. wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
  5. gunzip GeoIP.dat.gz

Download and install the Apache module

  1. wget http://www.maxmind.com/download/geoip/api/...ip_1.2.5.tar.gz
  2. tar xzfv mod_geoip_1.1.1.tar.gz
  3. cd mod_geoip_1.1.1
  4. apxs -cia -I/usr/local/include -L/usr/local/lib -lGeoIP mod_geoip.c

Server Configuration

In cPanel, I had to edit the Apache Configuration -> Includes Editor -> Post VirtualHost Include
Or you could edit./usr/local/apache/conf/includes/post_virtualhost_2.conf

  1. <IfModule mod_geoip.c>
  2. GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
  3. </IfModule>

cPanel users only, we need to distill the apxs module into Apache so it isn't lost next time you rebuild or upgrade cPanel/Apache.

  1. /usr/local/cpanel/bin/apache_conf_distiller -–update

Restart apache.

Here's a snippet of code that blocked 99% of spam from my client's UK based phpBB forum.

  1. # START Block Countries
  2. <IfModule mod_geoip.c>
  3. GeoIPEnable On
  4. RewriteEngine On
  5. RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(GB|US|IE|AU|PT)$
  6. RewriteRule ^(.*)$ http://<SITE>/access-denied [L]
  7. </IfModule>
  8. # END Block Countries

Related posts

  1. Auto Updating GeoIP Binary Databases
    Here's how I keep on top of updating the GeoIP binary databases used by various...
  2. Installing mod_evasive on cPanel and/or Apache
    This guide details how to install mod_evasive on cPanel to help protect against DDOS attacks,...
  3. [Snippet] Stupid Simple cPanel Install
    Open a clean server, Go have your lunch. Maybe lunch +VAT depending on the speed...
  4. Upgrading to MySQL 5.1 in cPanel/WHM
    Upgrading to MySQL 5.1 in cPanel is currently not the easiest thing in the world....
  5. Installing memcached on CentOS (cPanel)
    Welcome to hell. No really, compared to installing memcached on Ubuntu, CentOSs really sucks. CentOS...

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.