The Lazy Admin Blog

Home  /  Litespeed  /  Litespeed Geo Location Redirect

Litespeed Geo Location Redirect

September 14, 2020 Litespeed 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

Related Posts

  • Configure LiteSpeed Crawler

    October 5, 2022
  • Compiling PHP 5.2 on a CentOS 7 LiteSpeed Server

    Compiling PHP 5.2 on a CentOS 7 LiteSpeed Server

    October 1, 2022
  • Post-processing of the image failed likely because the server is busy.

    Post-processing of the image failed likely because the server is busy.

    September 30, 2022

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
Post Type Selectors
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
Emails
ESXI
iSCSI
JetBackup
Linux
Litespeed
MySQL
NGINX
Oracle
Reduxio
Security
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup bash CentOS cloudlinux cPanel CXS Emails freetds google htaccess IMAP InnoDB iscsi JetBackup Libmodsecurity litespeed modsec modsecurity mssql MySQL netapp nginx odbc Oracle php php.ini phpselector rsync ssh ssmtp systemd threads VMFS WHM Wordpress xenserver

Popular Posts

  • Convert JetBackup to cPanel structure October 6, 2022
  • How To Install & Configure a Galera Cluster with MariaDB on Centos 7 February 6, 2018
  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • rsync without prompting for password October 10, 2022

Recent Posts

  • Understanding Why More Threads Can Sometimes Slow Down Performance October 9, 2024
  • Set up a new systemd service May 18, 2024
  • Bash Arrays November 7, 2023
  • rsync without prompting for password October 10, 2022

Recent Comments

  • Sven on rsync without prompting for password
  • TheLazyAdmin on rsync without prompting for password
  • Sven on rsync without prompting for password
  • TheLazyAdmin on Convert JetBackup to cPanel structure
  • Chris on Convert JetBackup to cPanel structure
Privacy Policy • Contact