geoip
From WebHostingNeeds.com
Contents
GeoIP Download
GeoIP PHP
Install GeoIP
yum install -y zlib-devel
https://github.com/maxmind/geoip-api-c/releases
cd /usr/local/src wget https://github.com/maxmind/geoip-api-c/releases/download/v1.6.9/GeoIP-1.6.9.tar.gz tar zxvf GeoIP-1.6.9.tar.gz cd GeoIP-1.6.9 ./configure make make install
Install GeoIP Apache Module on CentOS
yum install -y httpd-devel git
Install GeoIP Apache Module on Ubuntu
apt-get install geoip-database geoip-bin libapache2-mod-geoip
Install GeoIP Apache Module from Source Code
cd /usr/local/src git clone https://github.com/maxmind/geoip-api-mod_geoip2.git cd geoip-api-mod_geoip2 apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c
Download Latest GeoIP database
mkdir /usr/local/share/GeoIP cd /usr/local/share/GeoIP mv GeoIP.dat GeoIP.dat_orig wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz gunzip GeoIP.dat.gz
Enable GeoIP in Apache
vi /etc/httpd/conf/httpd.conf
find
geoip_module
Add below
GeoIPEnable On GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat
To Block a web site, add following to VirtualHost entry of the web site.
Following code will redirect all traffic from China and Russia to http://scriptinstallation.in
RewriteEngine On RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CN|RU)$ RewriteRule ^(.*)$ http://scriptinstallation.in [L]
Auto Update GeoIP database
mkdir /usr/hostonnet/ vi /usr/hostonnet/geoip.sh
Add
#!/bin/bash cd /tmp wget -q http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz if [ -f GeoIP.dat.gz ] then gzip -d GeoIP.dat.gz /bin/rm -f /usr/local/share/GeoIP/GeoIP.dat /bin/mv -f GeoIP.dat /usr/local/share/GeoIP/GeoIP.dat else echo "The GeoIP library could not be downloaded and updated" fi
Make it executable
chmod 755 /usr/hostonnet/geoip.sh
Set cronjob to run it everyday
10 0 * * * /usr/hostonnet/geoip.sh 1> /dev/null 2> /dev/null
This cronjob will run everyday 10 minutes after midnight.