Are you interested for monthly server support with Unlimited tickets, 24×7 monitoring, Security Audit and lot more ? please check our Monthly server support plans

Block certain countries from accessing your web site:

You can block the access over certain countries to your website. This can be achieved by using the apache module Geo IP module.

This can be easily install and configure in your cPanel server. The main advantage of this module is the possibility of blocking various countries using the country code.

This is done by a module named mod_Geoip on the Apache. Below are the steps to enable and configure Geo IP on a cPanel servers,

Step 1.

First install binaries for GeoIP.

yum install GeoIP GeoIP-devel

Step 2.

 

Then you can download databases from MaxMind and put them into /opt/geoip/share/GeoIP/

http://geolite.maxmind.com/download/geoip/database/

Step 3.

Now install cPanel EasyApache GeoIP module. For that,

Run EasyApache and select mod GeoIP from

 /scripts/easyapache

Step 4.

Configure GeoIP by adding to httpd configuration file [ you can also add this to httpd conf by editing  pre_virtualhost_global.conf from WHM]

    /usr/local/apache/conf/httpd.conf
    /usr/local/apache/conf/includes/pre_virtualhost_global.conf

LoadModule geoip_module modules/mod_geoip.so
<IfModule mod_geoip.c>
  GeoIPEnable On
  GeoIPDBFile /var/lib/GeoIP.dat
</IfModule>

Step 5.

Now install GeoIP PHP Extension using the command below,

pecl install geoip

Step 6.

Restart Apache:

/scripts/restartsrv_apache

Now test if it is enabled by adding rules for that on .htaccess file on the public_html of the website. For that,

Edit the .htaccess file and add the following codes to it,

 

SetEnvIF GEOIP_COUNTRY_CODE AF BlockThese
SetEnvIF GEOIP_COUNTRY_CODE PK BlockThese
# Add more countries here
Deny from env=BlockThese

Here in the above code the country codes specified are,

AF and PK those belongs to countries AF Afghanistan and PK Pakistan.

You can see the list of all the country codes from the link below,

http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements

This is how to block the access of certain countries to your website.

Need our help to fix the issue ? Submit Support Ticket Now

[sep][/sep]

[button size=”large” color=”green” title=”Server Administration Services from Stack Supports” link=”http://iserversupport.com/server-support-products/server-security/”]View Server Administration Packages[/button]