This is an old revision of the document!
Enabling GeoLocation
IP2Location is a non-intrusive geo IP solution to help you to identify visitor's geographical location, i.e. 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 using a proprietary IP address lookup database and technology without invading the Internet user's privacy.
How to Enable
Install
Navigate to LiteSpeed Web Server directory:
cd /usr/local/lsws
Download and put IP2Location Database. You can use sample database from this address.
https://www.ip2location.com/developers#sample_ip2location_databases_bin
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:
- Click on Settings.
- Click Show advanced settings
- Scroll further down the list until you see System
- Click Open proxy settings
- Click the LAN settings button.
- On the Internet Properties window, click the LAN settings button.
- In the LAN Settings, uncheck the box that says Automatically detect settings.
- In the Proxy Server section, click the checkbox to enable
Use a proxy server for your LAN…
- In the Address field, enter the IP Address and Port Number of your Proxy Server.
- Press the OK button and then press OK again to save your settings.
- 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:
- Set Rewrite to
Yes
- For testing purpose, set Log Level to
9
. - Add the following rules to Rewrite Rules content:
# Redirect two specific countries RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(DE)$ RewriteRule ^(.*)$ https://en.wikipedia.org/wiki/Germany [R,L]
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
2
is match,-1
is not match
Troubleshooting
- If the module is not working, make sure that the httpd user (e.g.
nobody
) has read access to the IP2Location database file(s) you are using. - If the IP2Location variables do not show up please make sure that the client IP address is not on a private network such as 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16. IP2Location can only look up public IP addresses.