Install mod_geoip
sudo apt-get install libapache2-mod-geoip
The installation process creates a file /etc/apache2/mods-available/geoip.conf , ignore it and put the config info in apache2.conf , it will make it easier to find later.
Find these lines in /etc/apache2/apache2.conf
<Files ~ “^\.ht”>
Order allow,deny
Deny from all
</Files>
and paste these lines directly below
<Files *>
#check countries blocked on the ISO website http://www.iso.org/iso/country_codes.htm
#These countries are ranked by Worldpay as the countries where most fraudulent e-commerce transaction originate.
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
Order allow,deny
SetEnvIf GEOIP_COUNTRY_CODE PK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ID BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE YE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UA BlockCountry
Deny from env=BlockCountry
allow from all
</Files>
now restart apache
sudo apache2ctl restart
job done
