Requisites: Apache module, mod_maxminddb, libmaxminddb
INSTRUCTIONS:
1.Download and install libmaxminddb
[root@pidev ~]# git clone --recursive https://github.com/maxmind/libmaxminddb
[root@pidev ~]# cd libmaxminddb
[root@pidev libmaxminddb]# ./bootstrap
[root@pidev libmaxminddb]# ./configure
2.Run the following
[root@pidev libmaxminddb]# make
[root@pidev libmaxminddb]# make install
3. Download and install the Apache module mod_maxminddb
[root@pidev ~]# wget https://github.com/maxmind/mod_maxminddb/archive/master.zip
[root@pidev ~]# unzip master.zip
[root@pidev ~]# cd mod_maxminddb-master
[root@pidev mod_maxminddb-master]# ./bootstrap
4. Next,configure by specifying the full path of apxs
[root@pidev mod_maxminddb-master]# ./configure --with-apxs=/usr/sbin/apxs
[root@pidev mod_maxminddb-master]# make
[root@pidev mod_maxminddb-master]# make install
5.Download and extract GeoLite Country database
http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.Tar.gz
Note the path of GeoLite2-Country.mmdb
file.
6.Make sure you restart Apache web server.
[root@pidev ~]#/etc/init.d/httpd restart
7.Lastly add the following in the domain’s .htaccess
file (replace the full file path of GeoLite2-Country.mmdb in the server)
MaxMindDBEnable On MaxMindDBFile DB /usr/share/GeoIP/GeoLite2-Country_20170905/GeoLite2-Country.mmdb MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code #The below code will block access from Australia and France SetEnvIf MM_COUNTRY_CODE ^(AU|FR) BlockCountry Deny from env=BlockCountry