mod_geoip Revisted including stopping spam in phpBB 2
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
- wget http://www.maxmind.com/download/geoip/api/.../c/GeoIP.tar.gz
- tar xzfv GeoIP.tar.gz
- cd GeoIP-1.4.6/
- ./configure
- make
- make check
- 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
- mkdir /usr/share/GeoIP/
- cd /usr/share/GeoIP/
- mv GeoIP.dat GeoIP.dat_orig
- wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
- gunzip GeoIP.dat.gz
Download and install the Apache module
- wget http://www.maxmind.com/download/geoip/api/...ip_1.2.5.tar.gz
- tar xzfv mod_geoip_1.1.1.tar.gz
- cd mod_geoip_1.1.1
- 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
- <IfModule mod_geoip.c>
- GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
- </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.
/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.
- # START Block Countries
- <IfModule mod_geoip.c>
- GeoIPEnable On
- RewriteEngine On
- RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(GB|US|IE|AU|PT)$
- RewriteRule ^(.*)$ http://<SITE>/access-denied [L]
- </IfModule>
- # END Block Countries
Related posts
- Auto Updating GeoIP Binary Databases
Here's how I keep on top of updating the GeoIP binary databases used by various... - Installing mod_evasive on cPanel and/or Apache
This guide details how to install mod_evasive on cPanel to help protect against DDOS attacks,... - [Snippet] Stupid Simple cPanel Install
Open a clean server, Go have your lunch. Maybe lunch +VAT depending on the speed... - Upgrading to MySQL 5.1 in cPanel/WHM
Upgrading to MySQL 5.1 in cPanel is currently not the easiest thing in the world.... - Installing memcached on CentOS (cPanel)
Welcome to hell. No really, compared to installing memcached on Ubuntu, CentOSs really sucks. CentOS...


