IP2location Country Blocking

 In Amazon AWS

Create an account with ip2location, and access the free country blocking content:

sign in… (or create an account)

Click on Download, and under IP2Location Database, download the DB1.LITE IP_Countrt IPv4 database BIN file.

Then go to:


Download the Apache module.

IN the Installation steps, step number 2, you will see “Download IP2Location C library from here”, so click on the link to download the C Library as well.

You now have three files:


Create a directory, upload the files to it and unzip them as shown below:

(You can download a version of the files below from July 2022 if it helps for testing or to see what the files are…)

Installation details...
cd /home/ec2-user
mkdir ip2location
chmod 2775 ip2location
cd ip2location

[These are the files you will have: ip2location-apache-master.zip  IP2Location-C-Library-master.zip  IP2LOCATION-LITE-DB1.BIN.ZIP]

unzip ip2location-apache-master.zip
unzip IP2Location-C-Library-master.zip

[Check you have installed the following packages:]

dnf -y install autoconf automake libtool httpd-devel

cd IP2Location-C-Library-master
vi Makefile.am
[After the line AM_CPPFLAGS add the following:]
[Save and exit the editor]

vi configure.ac
[After the line AC_C_BIGENDIAN add the following:]
[After the line AC_PROG_LIBTOOL add the following:]
[Save and exit the editor]

[Run these commands:]

mkdir m4
autoreconf -i -v --force
make install

[Run these commands:]

cd ..
cd ip2location-apache-master
apxs -i -a -L /usr/local/lib/ -I ../IP2Location-C-Library-master/libIP2Location/ -l IP2Location -c mod_ip2location.c
ln -s /usr/local/lib/libIP2Location.so.1 /usr/lib/libIP2Location.so.1

[Then add these lines to the end of your /etc/httpd/conf/httpd.conf file:]

<IfModule mod_ip2location.c>
    IP2LocationEnable On
    IP2LocationDetectProxy On
    IP2LocationSetmode ALL
    IP2LocationDBFile /home/ec2-user/ip2location/IP2LOCATION-LITE-DB1.BIN

[You will notice this new line: LoadModule IP2Location_module /usr/lib64/httpd/modules/mod_ip2location.so is now in httpd.conf]

[Fix file permissions:]

cd /home/ec2-user/ip2location
find . -type d -exec sudo chmod 2775 {} \;
find . -type f -exec sudo chmod 0664 {} \;
chmod 777 /home/ec2-user/ip2location/IP2LOCATION-LITE-DB1.BIN
cd /home/ec2-user
chown apache ip2location
chgrp ec2-user ip2location

[Restart httpd:]

systemctl restart httpd

Use the IBM 2 letter country codes to select your countries, and add lines like these near the top of your .htaccess file:
I place the lines below my https redirect lines: (use your own domain name)
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain.au/$1 [R,L]

vi /var/www/html/.htaccess

RewriteRule ^(.*)$ https://google.com.au [L]
RewriteRule ^(.*)$ https://google.com.au [L]

Start typing and press Enter to search