Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
litespeed_wiki:lslb:geoip [2019/08/28 19:53] Lisa Clarke Copyediting |
litespeed_wiki:lslb:geoip [2020/11/18 15:43] Lisa Clarke Redirect to new Documentation Site |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== How to enable GeoIP on ADC? ====== | + | ~~REDIRECT>https://docs.litespeedtech.com/products/lsadc/settings/~~ |
- | + | ||
- | 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 time, so choose your favorite and stick with that one. | + | |
- | + | ||
- | 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. | + | |
- | + | ||
- | {{:litespeed_wiki:lslb:adc-geoip-11.png?800|}} | + | |
- | + | ||
- | ===== Enable GeoLocation Lookup ===== | + | |
- | Set **Enable GeoLocation Lookup** to ''Yes''. This must be set, if you want Geolocation to work on Web ADC. | + | |
- | + | ||
- | ===== 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 ==== | + | |
- | + | ||
- | === Download and Install === | + | |
- | 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/'', like so: | + | |
- | <code> | + | |
- | wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz | + | |
- | tar -zxvf GeoLite2-Country.tar.gz | + | |
- | </code> | + | |
- | + | ||
- | Then, move the file ''GeoLite2-Country.mmdb'' to ''/usr/share/GeoIP/GeoLite2-Country.mmdb''. | + | |
- | + | ||
- | === 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 cannot 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**, 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. | + | |
- | + | ||
- | ==== 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'' | + | |
- | * A space | + | |
- | * The logical name of the environment variable, which consists of: | + | |
- | * The name of the database as specified in the **DB Name** field as the prefix. For example, ''COUNTRY_DB'' | + | |
- | * A forward slash ''/'' | + | |
- | * The name of the field as displayed in ''mmdblookup''. For example: ''country/names/en'' | + | |
- | + | ||
- | Thus the default generates: | + | |
- | + | ||
- | GEOIP_COUNTRY_NAME COUNTRY_DB/country/names/en | + | |
- | + | ||
- | If you wanted the country code to be displayed in Spanish, you would enter the environment variable: | + | |
- | + | ||
- | GEOIP_COUNTRY_NAME COUNTRY_DB/country/names/es | + | |
- | + | ||
- | Note that if a variable is used by multiple databases (for example, the default ''GEOIP_COUNTRY_NAME''), you need to override the value in the last database specified (or all databases in case they get reordered, just to be safe). | + | |
- | + | ||
- | Note that ''subdivisions'' is an array and must be referenced by index (usually ''0'' or ''1''). | + | |
- | + | ||
- | The default environment variables vary by database and are designed to be as similar to the legacy GeoIP environment variables as possible. | + | |
- | + | ||
- | Our default list is: | + | |
- | + | ||
- | "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" | + | |
- | + | ||
- | You can customize the configuration to add the environment variables you want as describe above. | + | |
- | + | ||
- | === Example 1 === | + | |
- | Make sure the entry name is correct. | + | |
- | + | ||
- | You can add the following: | + | |
- | GEOIP_REGION_NAME CITY_DB/subdivisions/0/names/en | + | |
- | Please make sure the correct entry name is used. For example, the following is incorrect: ''name'' should be ''names''. | + | |
- | GEOIP_REGION_NAME CITY_DB/subdivisions/0/name/en | + | |
- | + | ||
- | === Example 2 === | + | |
- | You can customize a name as ''MyTest_COUNTRY_CODE'', like so: | + | |
- | MyTest_COUNTRY_CODE CITY_DB/country/iso_code | + | |
- | + | ||
- | {{ :litespeed_wiki:cache:common:litespeed-geoip2-variables-e1.png?800 |}} | + | |
- | + | ||
- | ''US'' will be replaced by the country code you are visiting from, such as ''SG'' or others. | + | |
- | + | ||
- | === Example 3 === | + | |
- | You can customize a name as ''MyTest2_COUNTRY_CODE'' by using a defined COUNTRY DB name ''COUNTRY_DB_20190402'' with a country database. | + | |
- | MyTest2_COUNTRY_CODE COUNTRY_DB_20190402/country/iso_code | + | |
- | {{ :litespeed_wiki:cache:common:litespeed-geoip2-variables-e2.png?800 |}} | + | |
- | + | ||
- | === Example 4 === | + | |
- | + | ||
- | You can customize all of the following: | + | |
- | HTTP_GEOIP_CITY CITY_DB/city/names/en | + | |
- | HTTP_GEOIP_POSTAL_CODE CITY_DB/postal/code | + | |
- | HTTP_GEOIP_CITY_CONTINENT_CODE CITY_DB/continent/code | + | |
- | HTTP_GEOIP_CITY_COUNTRY_CODE CITY_DB/country/iso_code | + | |
- | HTTP_GEOIP_CITY_COUNTRY_NAME CITY_DB/country/names/en | + | |
- | HTTP_GEOIP_REGION CITY_DB/subdivisions/0/iso_code | + | |
- | HTTP_GEOIP_LATITUDE CITY_DB/location/latitude | + | |
- | HTTP_GEOIP_LONGITUDE CITY_DB/location/longitude | + | |
- | + | ||
- | {{ :litespeed_wiki:cache:common:litespeed-geoip2-variables-e4-1.png?600 |}} | + | |
- | + | ||
- | + | ||
- | === 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 ==== | + | |
- | 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 ===== | + | |
- | This example test case redirects all US IPs to the ''/en/'' site. | + | |
- | In the **Rewrite** tab under **example.com** ADC virtual host, **Rewrite Control**, set **Enable Rewrite** to ''Yes''. | + | |
- | + | ||
- | Then added the following to **Rewrite Rules**: | + | |
- | RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ | + | |
- | RewriteRule ^.*$ https://example.com/en [R,L] | + | |
- | + | ||
- | Visiting ''example.com'' through a US IP should redirect to ''https://example.com/en'' successfully. | + | |
- | {{:litespeed_wiki:lslb:adc-geoip-2-vh-rewriterules.png?800|}} | + | |
- | + |