Block Countries using mod_geoip in cPanel

June 27, 2013 — 2 Comments

Yesterday, I wrote an article on how to block certain countries from your server using csf. This will block them from accessing your server on any port. You can, however use mod_geoip if you’d like to block them from accessing your web site(s). You might want to do this if the csf approach creates too many iptables rules for your server to handle.

This is an article on how to install and use mod_geoip2 in cpanel.  The short version is that you download it, extract it into the easyapache custom modules directory, then run easyapache to enable it.

Here’s the detailed version.

1. SSH to your server as root.

2. Grab the lastest version from cPanel:

(If that link does not work, view the cPanel custom modules page to get the correct link)

3. Unpack it into cPanel’s easyapache dir:

4. Run easyapache in choose the mod_geoip option


5. Save and build your easyapache choices

6. Tell apache about the GeoIP dat file:

Edit /usr/local/apache/conf/includes/pre_main_global.conf and add the following into it:

Restart apache:

7. Start blocking!

- Server wide:

Edit /usr/local/apache/conf/includes/pre_main_global.conf again and make it look like this:

This will block Russia, China and Thailand access globally to all websites on the server.

Restart apache:

- Site by site:

Add the following into an .htaccess file for your website in its DocumentRoot

This will block Russia, China and Thailand access to that website.

If you’d rather only allow certain countries, use something like this:

You can view a full list of countries here:

More mod_geoip2 information:

If you need assistance with this, I’d be more than happy to set this up for you.  You can contact me through my Linux support site.

2 responses to Block Countries using mod_geoip in cPanel

  1. Users from certain countries are up to no good a lot of the time. Blocking them will come in very handy. Thank you for your offer of assistance as well, very kind of you.

  2. yaa thats true thanks

Leave a Reply