Blocking Traffic With Apache GeoIP Module

To install GeoIP module in CentOS Apache server, run

yum install -y GeoIP mod_geoip

Now verify mod_geoip installed in apache by running

httpd -M | grep geoip

Example

[root@3blogger ~]# httpd -M | grep geoip
 geoip_module (shared)
[root@3blogger ~]# 

Now edit /etc/httpd/conf/httpd.conf

vi /etc/httpd/conf/httpd.conf

add following

GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat

In your Apache VirtualHost, add

RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(A1|RU)$
RewriteRule ^(.*)$ http://scriptinstallation.in [L]

This will block access from A1 (proxy IP) and RU. You can use any 2 letter code of any country to block traffic from the country.


Posted in Apache