Table of Contents

Enabling IP2Location

IP2Location is a non-intrusive GeoIP solution to help you to identify visitor's geographical location, providing information such as country, region, city, latitude & longitude of city, ZIP code, time zone, connection speed, ISP, domain name, IDD country code, area code, weather station code and name, mobile carrier, elevation and usage type information. IP2Location uses a proprietary IP address lookup database and technology that doesn't invade the Internet user's privacy.

How to Enable

Install

Navigate to LiteSpeed Web Server directory:

 cd /usr/local/lsws 

Download any sample database from IP2location and save to this directory.

Setup

In LSWS WebAdmin, configure the database location. Navigate to Configuration > Server > General > General settings > IP2Location DB
Enter DB File Path:

/usr/local/lsws/IP-COUNTRY-SAMPLE.BIN

Set DB Cache Type to MemoryCache

Navigate to Web Admin > Configurations > Your Virtual Hosts > Rewrite to add rewrite rules that will control the redirect:

<IfModule LiteSpeed>
  RewriteEngine On
  RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^DE$
  RewriteRule ^(.*)$ http://www.google.co.uk [L]
</IfModule>

Refer to Ip2location for more rewrite examples.

How to Verify

Change Your Source IP by Proxy

Method 1:

From this site , we can simply put in a web IP and choose a country from three(USA, Germany, Netherlands). If you want more than three countries, then you need to register for a paid plan.

Method 2:

You can choose a free proxy server from online free resources, e.g. Free_Proxy

Setup the proxy IP with your browser. Here are the steps for Chrome:

  1. Click on Settings.
  2. Click Show advanced settings
  3. Scroll further down the list until you see System
  4. Click Open proxy settings
  5. Click the LAN settings button.
  6. On the Internet Properties window, click the LAN settings button.
  7. In the LAN Settings, uncheck the box that says Automatically detect settings.
  8. In the Proxy Server section, click the checkbox to enable Use a proxy server for your LAN
  9. In the Address field, enter the IP Address and Port Number of your Proxy Server.
  10. Press the OK button and then press OK again to save your settings.
  11. Now when you surf the web, you will be surfing by using the Proxy Server.

Set Rewrite Rules

Navigate to Web Admin > Configurations > Your Virtual Hosts > Rewrite:

Log

 tail -f /PATH_TO_LSWS/log/error.log 

When you are using Germany IP:

[REWRITE] Rule: Match '/' with pattern '^(.*)$', result: 2
[REWRITE] Cond: Match 'DE' with pattern '^(DE)$', result: 2
[REWRITE] Source URI: '/' => Result URI: 'https://en.wikipedia.org/wiki/Germany'

When you are using Netherlands IP:

[REWRITE] Rule: Match '/' with pattern '^(.*)$', result: 2
[REWRITE] Cond: Match 'NL' with pattern '^(DE)$', result: -1

Note: 2 is a match, -1 is not a match

Troubleshooting

More Information