Okay we continue to the third part of this post title, on the previous part we use NginX as load balancer and failover, now we use NginX with Geo IP based to determine the best backend for the visitors to put, here is the illustration.
For instance, we have two backend servers located in UK and DE, then we put the visitors from United Kingdom to the UK backend, visitors from Germany to DE backend, and the rest will be divided into those two backend servers, let’s deal with it.
I assume you have installed NginX in your frontend and two backend servers, you can check the previous post for NginX installation. This GeoIP based location needs GeoIP database for the frontend server to determine where to put the visitor, so first we download and extract Lite version of GeoIP database from Maxmind with geo2nginx.pl script from http://markmaunder.com.
wget https://serversreview.net/pkgs/txt/geo2nginx.pl chmod 755 geo2nginx.pl wget http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip unzip GeoIPCountryCSV.zip ./geo2nginx.pl < GeoIPCountryWhois.csv > geo.conf mv geo.conf /etc/nginx/
GeoIP database has been added to NginX directory, now to the configuration, here is the example of main configuration