Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
litespeed_wiki:lslb:geoip [2019/08/27 19:11]
Jackson Zhang created
litespeed_wiki:lslb:geoip [2019/08/28 19:53]
Lisa Clarke Copyediting
Line 1: Line 1:
-====== How to enable ​GEOIP on ADC? ====== +====== How to enable ​GeoIP on ADC? ======
-There are two sections in the LiteSpeed ADC WEB Admin Console settings: **IP to GeoLocation DB** and **IP2Location DB**. Both the MaxMind legacy db and MaxMind GeoIP2 db should use the **IP to GeoLocation DB** section. ​ Don't use **IP2Location DB** for MaxMind GeoIP2 database since **IP2Location DB** is meant for the  [[https://​www.ip2location.com/​|IP2Location database]]. ​ You should only use one location database at a time. +
  
-To setup and enable GeoIP on LiteSpeed ADC, you will need to choose one database, download ​and install ​the database to a directory, setup the database ​path in ADC Admin''​Enable GeoLocation Lookup''​ should set to ''​Yes''​then set rewrite rules in virtual host rewrite tab and finally run some tests+There are two location database settings in LiteSpeed ​Web ADC's WebAdmin Console. The MaxMind legacy ​database and the MaxMind GeoIP2 ​database ​both use the **IP to GeoLocation DB** setting. The **IP2Location DB** setting is meant for the [[https://​www.ip2location.com/​|IP2Location database]]. This guide will show you hot to set up both types of Geolocation ​database, ​but you will not need to use both. You can only use one location database at a timeso choose your favorite ​and stick with that one.
  
-{{:​litespeed_wiki:​lslb:​adc-geoip-1.png?800|}}+Setting up and enabling GeoIP on LiteSpeed ADC involves choosing a database, downloading and installing the database to a directory, setting up the database path in ADC Admin, enabling geolocation lookup, setting rewrite rules, and finally, running some tests
  
-===== set ''​Enable GeoLocation Lookup''​ to ''​Yes''​ ===== +{{:​litespeed_wiki:​lslb:​adc-geoip-11.png?800|}}
-First, you should set ''​Enable GeoLocation Lookup''​ to ''​Yes''​. Without setting this, ADC won't look up GEOIP+
  
-===== Download and Configure GEOIP Database Path =====+===== Enable GeoLocation Lookup ​===== 
 +Set **Enable GeoLocation Lookup** to ''​Yes''​. This must be set, if you want Geolocation to work on Web ADC.
  
-You will need to choose only one database to be used for your GeoIP: MaxMind GeoIP2, MaxMind Legacy Database, or IP2location database. Then, set up the right database path in the appropriate section in the ADC Web Admin Console. ​  +===== Download and Configure ===== 
 +Choose ​your favorite database: MaxMind GeoIP2, MaxMind Legacy Database, or IP2location database. Then, set up the correct ​database path in the appropriate section in the ADC WebAdmin ​Console, as described.   
  
 ==== MaxMind GeoIP2 Database ====  ==== MaxMind GeoIP2 Database ==== 
  
-=== Download and Install ​Database=== +=== Download and Install === 
 Let's assume that you will store the DB in ''/​usr/​share/​GeoIP/''​. Let's assume that you will store the DB in ''/​usr/​share/​GeoIP/''​.
  
-Download the free database from ''​https://​dev.maxmind.com/​geoip/​geoip2/​geolite2/'':​ +Download the free database from ''​https://​dev.maxmind.com/​geoip/​geoip2/​geolite2/''​, like so
-  wget http://​geolite.maxmind.com/​download/​geoip/​database/​GeoLite2-Country.tar.gz+<​code>​ 
 + wget http://​geolite.maxmind.com/​download/​geoip/​database/​GeoLite2-Country.tar.gz
   tar -zxvf GeoLite2-Country.tar.gz   tar -zxvf GeoLite2-Country.tar.gz
 +</​code>​
  
-Then, move the file ''​GeoLite2-Country.mmdb''​ to  +Then, move the file ''​GeoLite2-Country.mmdb''​ to ''​/​usr/​share/​GeoIP/​GeoLite2-Country.mmdb''​.
-  ​/​usr/​share/​GeoIP/​GeoLite2-Country.mmdb+
   ​   ​
 === Set up Database File Path and Name === === Set up Database File Path and Name ===
-In ADC WebAdmin, configure the database location and name(Both **DB File Path** and **DB Name** are mandatory and can not be empty). Your choice of DB name is important: you must use ''​COUNTRY_DB''​ for a country database, and ''​CITY_DB''​ for a city database. Navigate to **Configuration > Server > General > General settings** and set  **MaxMind GeoIP DB]]** to the database path. Then set **DB Name** to ''​COUNTRY_DB''​ or ''​CITY_DB''​. **Environment Variables** and **Notes** are optional.+In ADC WebAdmin, configure the database location and name(Both **DB File Path** and **DB Name** are mandatory and cannot ​be empty.
  
-==== Advanced Configuration:GEOIP2 Environment Variables ====+Your choice of DB name is importantyou must use ''​COUNTRY_DB''​ for a country database, and ''​CITY_DB''​ for a city database. Navigate to **Configuration > Server > General**, and set **MaxMind GeoIP DB** to the database path. Then set **DB Name** to ''​COUNTRY_DB''​ or ''​CITY_DB''​. ​
  
-The full power of GeoIP2 requires the use of environment variables in the LiteSpeed configuration. The format used is designed to be as similar as possible to the Apache ''​mod_maxminddb''​ environment described [[https://​github.com/​maxmind/​mod_maxminddb|here]] ,​specifically for the ''​MaxMindDBEnv''​ variable. ​ Each environment variable is specified in the environment text box as one line:+**Environment Variables** and **Notes** are optional. 
 + 
 +==== Advanced Configuration:​ GeoIP2 Environment Variables ==== 
 + 
 +The full power of GeoIP2 requires the use of environment variables in the LiteSpeed configuration. The format used is designed to be as similar as possible to the Apache ''​mod_maxminddb''​ environment described [[https://​github.com/​maxmind/​mod_maxminddb|here]],​ specifically for the ''​MaxMindDBEnv''​ variable. ​ Each environment variable is specified in the environment text box as one line:
  
   * The name of the environment variable that will be exported, for example ''​GEOIP_COUNTRY_NAME''​   * The name of the environment variable that will be exported, for example ''​GEOIP_COUNTRY_NAME''​
Line 80: Line 85:
 {{ :​litespeed_wiki:​cache:​common:​litespeed-geoip2-variables-e1.png?​800 |}} {{ :​litespeed_wiki:​cache:​common:​litespeed-geoip2-variables-e1.png?​800 |}}
  
-It will show on the ''​phpinfo.php''​ page as: 
-   ​_SERVER["​MyTest_COUNTRY_CODE"​] ​ US 
 ''​US''​ will be replaced by the country code you are visiting from, such as ''​SG''​ or others. ''​US''​ will be replaced by the country code you are visiting from, such as ''​SG''​ or others.
  
Line 88: Line 91:
   MyTest2_COUNTRY_CODE COUNTRY_DB_20190402/​country/​iso_code   MyTest2_COUNTRY_CODE COUNTRY_DB_20190402/​country/​iso_code
 {{ :​litespeed_wiki:​cache:​common:​litespeed-geoip2-variables-e2.png?​800 |}}  ​ {{ :​litespeed_wiki:​cache:​common:​litespeed-geoip2-variables-e2.png?​800 |}}  ​
-It will show on the ''​phpinfo.php''​ page as: 
-  _SERVER["​MyTest2_COUNTRY_CODE"​] US 
  
 === Example 4 === === Example 4 ===
Line 105: Line 106:
 {{ :​litespeed_wiki:​cache:​common:​litespeed-geoip2-variables-e4-1.png?​600 |}} {{ :​litespeed_wiki:​cache:​common:​litespeed-geoip2-variables-e4-1.png?​600 |}}
  
-It will show on the ''​phpinfo.php''​ page as: 
-  _SERVER["​HTTP_GEOIP_CITY"​] Montville 
-  _SERVER["​HTTP_GEOIP_POSTAL_CODE"​] 07045 
-  _SERVER["​HTTP_GEOIP_CITY_CONTINENT_CODE"​] NA 
-  _SERVER["​HTTP_GEOIP_CITY_COUNTRY_CODE"​] US 
-  _SERVER["​HTTP_GEOIP_CITY_COUNTRY_NAME"​] United States 
-  _SERVER["​HTTP_GEOIP_REGION"​] NJ 
-  _SERVER["​HTTP_GEOIP_LATITUDE"​] 40.90490 
-  _SERVER["​HTTP_GEOIP_LONGITUDE"​] -74.36460 
- 
-{{ :​litespeed_wiki:​cache:​common:​litespeed-geoip2-variables-e4-2.png?​400 |}} 
- 
-=== Setup Database File Path === 
-In ADC WebAdmin, configure the database location: Navigate to **Configuration > Server > General > set  **MaxMind GeoIP DB** to the database path.  
  
 +=== Set up Database File Path ===
 +In ADC WebAdmin, configure the database location: Navigate to **Configuration > Server > General **, and set  ''​MaxMind GeoIP DB''​ to the database path. 
  
 ==== IP2Location Database ==== ==== IP2Location Database ====
-You can download the IP2Location Database from [[https://​www.ip2location.com/​|their website]] and configure the **IP2Location DB File Path** in the **IP2Location DB** section.  ​+You can download the IP2Location Database from [[https://​www.ip2location.com/​|the IP2Location ​website]] and configure the **IP2Location DB File Path** in the **IP2Location DB** section.  ​
  
 ===== Testing ===== ===== Testing =====
-This example test case is to redirect ​all US IP to /en/ site. +This example test case redirects ​all US IPs to the ''​/en/'' ​site. 
-In ''​Rewrite'' ​tab under ''​example.com'' ​ADC virtualhost''​Rewrite Control''​ -> Set ''​Enable Rewrite'' ​to ''​Yes''​.+In the **Rewrite** tab under **example.com** ADC virtual host**Rewrite Control**, set **Enable Rewrite** to ''​Yes''​.
  
-Then added the following to ''​Rewrite Rules''​:+Then added the following to **Rewrite Rules**:
   RewriteCond %{ENV:​GEOIP_COUNTRY_CODE} ^US$   RewriteCond %{ENV:​GEOIP_COUNTRY_CODE} ^US$
   RewriteRule ^.*$ https://​example.com/​en [R,L]   RewriteRule ^.*$ https://​example.com/​en [R,L]
   ​   ​
-Visiting example.com through US IP should redirect to ''​https://​example.com/​en''​ successfully.+Visiting ​''​example.com'' ​through ​US IP should redirect to ''​https://​example.com/​en''​ successfully.
 {{:​litespeed_wiki:​lslb:​adc-geoip-2-vh-rewriterules.png?​800|}} {{:​litespeed_wiki:​lslb:​adc-geoip-2-vh-rewriterules.png?​800|}}
  
  
  • Admin
  • Last modified: 2020/11/18 15:43
  • by Lisa Clarke