====== 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 [[https://www.ip2location.com/developers#sample_ip2location_databases_bin|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 > [[https://www.litespeedtech.com/docs/webserver/config/general#ip2locDBFile|IP2Location DB]]** \\
Enter **DB File Path**:
/usr/local/lsws/IP-COUNTRY-SAMPLE.BIN
Set **DB Cache Type** to ''MemoryCache''\\
{{:litespeed_wiki:config:ip2loc.png?900|}}
Navigate to **Web Admin > Configurations > Your Virtual Hosts > Rewrite** to add rewrite rules that will control the redirect:
RewriteEngine On
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^DE$
RewriteRule ^(.*)$ http://www.google.co.uk [L]
Refer to [[https://www.ip2location.com/free/visitor-redirection#source-codes | Ip2location]] for more rewrite examples.
=====How to Verify =====
====Change Your Source IP by Proxy====
===Method 1:===
From [[https://hide.me/en/proxy | 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. \\
{{:litespeed_wiki:config:geo-3.png?600|}}
===Method 2:===
You can choose a free proxy server from online free resources, e.g. [[ https://free-proxy-list.net/ | Free_Proxy]] \\
{{:litespeed_wiki:config:geo-1.png?600|}}\\
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
Note: ''2'' is a match, ''-1'' is not a 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.
===== More Information =====
* [[https://www.ip2location.com/free/country-information | IP Country Codes List:]]