Jetserver – The Lazy Admin Blog
Home  /  Litespeed  /  Litespeed Geo Location Redirect

Litespeed Geo Location Redirect

elialum September 14, 2020 Leave a Comment

Here we will use a geolocation DB combined with a Litespeed webserver to redirect visitors on our site to a different version or language of the site based on their location.

In this example, we are using Centos 7 and have the server up and running with a Litespeed web server.

The first thing we going to install GeoIP packages:

#yum install -y geoip geoipupdate

Next, we will need is a Geolocation DB, our DB of choice is MaxMind GeoLite2, due to licensing changes we will need to sign up for the service at https://www.maxmind.com/en/geolite2/signup

After we successfully opened an account and logged in we will need to generate a license at Services > My License Key > Generating new license key

CentOS 7 uses geoipupdate 2.5 so we will choose to generate the key for versions older than 3.1.1 and after confirming click on Download Config and save this file. Now that we have the license, let’s edit “/etc/GeoIP.conf” and replace the content with what we just got from MaxMind.

Geoipupdate is setup now lets run the update:

#/usr/bin/geoipupdate

this will download the databases to /usr/share/GeoIP
It’s recommended to create a cron for geoipupdate once a month to keep it up to date.

Now that we have geoip packages and DB let’s configure LiteSpeed,
Login to Litespeed admin panel go to Server > General Settings > Edit and Enable GeoLocation Lookup, and in Server > MaxMind GeoIP DB > add

DB location we downloaded earlier: /usr/share/GeoIP/GeoLite2-Country.mmdb
db name (in this case): DB Name

Save & Graceful Restart.

All should be set now! We can go to our site .htaccess file or Rewrite Rules in Litespeed admin panel and add the required rules for our use case.
Here are a few examples:

#Redirect visitor from Poland to the polish version of the site
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(PL)$
RewriteCond %{REQUEST_URI} !^/pl
RewriteRule ^(.*)$ /pl [R=301,L]

                   
#Redirect visitors from Poland to other domain.
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(PL)$
RewriteRule ^(.*)$ https://domain.pl [R=301,L]

”PL” is an example of iso country code of Poland, we can replace or add other country codes.

GEOIP_COUNTRY_CODE is one of the default environment variable Litespeed set:

"GEOIP_COUNTRY_CODE", "/country/iso_code" 
"GEOIP_CONTINENT_CODE", "/continent/code" 
"GEOIP_REGION", "/subdivisions/0/iso_code"
"GEOIP_METRO_CODE", "/location/metro_code"
"GEOIP_LATITUDE", "/location/latitude"
"GEOIP_LONGITUDE", "/location/longitude"
"GEOIP_POSTAL_CODE", "/postal/code"
"GEOIP_CITY", "/city/names/en"

under Server > MaxMind GeoIP DB we can set our own variable as needed.

Tags: litespeed
Previous Article
Next Article

About Author

elialum

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search Our Blog

Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
ESXI
iSCSI
JetBackup
Litespeed
MySQL
NGINX
Reduxio
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup CentOS cloudlinux cPanel CXS freetds google htaccess iscsi JetBackup Libmodsecurity litespeed modsec modsecurity mssql MySQL netapp nginx odbc php php.ini phpselector VMFS WHM xenserver

Popular Posts

  • How To Install & Configure a Galera Cluster with MySQL on Centos 7 February 6, 2018
  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • Libmodsecurity installation April 14, 2016
  • JetBackup Cheat Sheet :: Automatically Acknowledge Alerts November 15, 2018

Recent Posts

  • Dealing with aggressive bot scanners September 14, 2020
  • Litespeed Geo Location Redirect September 14, 2020
  • JetBackup :: Restore on steroids ! August 21, 2020
  • XENSERVER :: CONNECTING ISCSI SR NETAPP STORAGE September 4, 2019

Recent Comments

  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Oleg Drabkin on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Daniel on How To Install & Configure a Galera Cluster with MySQL on Centos 7
אחסון אתרים | JetApps