- Step one login to your server. I personally just ‘su root’ instead of ‘sudo’ all the time, but I’m lady, and confident I won’t ‘rm -rf /lib’ or something equally as asinine.
- Now you’re going to want to issue this command;
1# yum install GeoIP GeoIP-devel GeoIP-data zlib-devel - Then, we’re going to want to issue the following to create the GeoIP directory, and enter it
1# mkdir /usr/share/GeoIP && cd /usr/share/GeoIP - Now we’ll want to grab the data files from MaxMind. These commands with download the city and country info.
1234# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz# gunzip GeoIP.dat.gz# gunzip GeoLiteCity.dat.gz - Now we’re going to want to install some requirements for everything to build. If you already have something installed from this list it will just ignore it and install the rest.
1# yum install httpd-devel apr-devel ea-apache24-devel.x86_64 ea-apache24-tools.x86_64 wget nano
в моем случае достаточно было установить:
1yum install ea-apache24-devel cyrus-sasl-devel ea-apr-devel ea-apr-util-developenldap-devel - Now you’re going to want to grab the GeoIP source for apache module. Then, uncompress it, and, enter the directory.
12# wget ftp://ftp.netbsd.org/pub/pkgsrc/distfiles/mod_geoip2_1.2.5.tar.gz# tar xvzf mod_geoip2_1.2.5.tar.gz && cd mod_geoip2_1.2.5 - Now we have to make a change due to apache 2.4 and some name changes, so, run this command now.
1# sed s/remote_ip/client_ip/g -i mod_geoip.c - And finally we can go ahead and compile the module.
1# apxs -i -a -L/usr/lib64 -I/usr/include -lGeoIP -c mod_geoip.c - Now we just have to modify the httpd.conf file for Apache to load the module
1# nano /etc/apache2/conf.modules.d/mod_geoip.conf - Change the content of this file so instead of looking like this;
1LoadModule geoip_module /usr/lib64/apache2/modules/mod_geoip.so
instead, make sure it looks like this;
1234567LoadModule geoip_module /usr/lib64/apache2/modules/mod_geoip.so<IfModule mod_geoip.c>GeoIPEnable OnGeoIPDBFile /usr/share/GeoIP/GeoIP.dat StandardGeoIPDBFile /usr/share/GeoIP/GeoLiteCity.dat Standard</IfModule>
Then, exit and save the file. - Now you’ll want to restart apache.
1# service httpd restart && apachectl restart - Then you can go ahead and create an info file and check via the web if geoip is supported.
1# nano /var/www/info.php - Put these contents in it
1<?php phpinfo(); ?> - Close and exit the file, then visit your site at http://YOUR_DOMAIN.COM/info.php and you should see something similar to the following.
- Congrats, you’re done!
Для конфигурации конкретного виртуального хоста, можно воспольщзоваться .htaccess в таком случае содержимое файла должно быть следующим:
#GeoIPEnable On
SetEnvIf GEOIP_COUNTRY_CODE UA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KZ BlockCountry
Deny from env=BlockCountry
Allow from <YOUR excluded IP>
Для глобавльной конфигурации apache