Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
litespeed_wiki:cache:common:geoip-support [2019/04/16 16:20]
Jackson Zhang [MaxMind GeoIP2 Database]
litespeed_wiki:cache:common:geoip-support [2019/04/16 20:25]
Jackson Zhang
Line 46: Line 46:
   </​code>​   </​code>​
  
-=== GEOIP2 Envirment Variables ===+==== Advanced Configuration:​GEOIP2 Envirment Variables ​====
  
 The full power of the GeoIP2 facility requires use of the environment variables in the Litespeed Configuration. ​ The description of the format used is designed to be as similar as possible as 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 full power of the GeoIP2 facility requires use of the environment variables in the Litespeed Configuration. ​ The description of the format used is designed to be as similar as possible as 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:
Line 85: Line 85:
 You can customize the configuration to add the environment variables you want as describe above. ​ You can customize the configuration to add the environment variables you want as describe above. ​
  
-Example 1: Make sure the entry name correct:+=== Example 1: Make sure the entry name correct ​===
  
 you can add the following. ​ you can add the following. ​
Line 92: Line 92:
   GEOIP_REGION_NAME CITY_DB/​subdivisions/​0/​name/​en   GEOIP_REGION_NAME CITY_DB/​subdivisions/​0/​name/​en
  
-Example 2+=== Example 2 === 
 You can customize a name as "​MyTest_COUNTRY_CODE"​ as the following: You can customize a name as "​MyTest_COUNTRY_CODE"​ as the following:
   MyTest_COUNTRY_CODE CITY_DB/​country/​iso_code   MyTest_COUNTRY_CODE CITY_DB/​country/​iso_code
Line 102: Line 102:
 "​US"​ will be replaced by your country code visiting from, such "​SG"​ or others. "​US"​ will be replaced by your country code visiting from, such "​SG"​ or others.
  
-Example 3:+=== Example 3 ===
 You can customize a name as "​MyTest2_COUNTRY_CODE"​ by using a defined COUNTRY DB name "​COUNTRY_DB_20190402"​ with a contry database. You can customize a name as "​MyTest2_COUNTRY_CODE"​ by using a defined COUNTRY DB name "​COUNTRY_DB_20190402"​ with a contry database.
   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 |}}  ​
 It will show from phpinfo.php page as: It will show from phpinfo.php page as:
   _SERVER["​MyTest2_COUNTRY_CODE"​] US   _SERVER["​MyTest2_COUNTRY_CODE"​] US
  
 +=== Example 4 ===
 +
 +You can customize like 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 |}}
 +
 +The following will show in phpinfo.php page:
 +  _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 |}}
  
 ==== MaxMind Legacy Database ==== ==== MaxMind Legacy Database ====
Line 237: Line 261:
   ​   ​
 GeoIP rewrite rules that do not work as expected may be more complicated. You will need to check the rules to look for issues such as a redirect loop. When needed, you can log a ticket with us. Let us know the rules set is not working as expected, and provide a more detailed test example for us to take a further look.  GeoIP rewrite rules that do not work as expected may be more complicated. You will need to check the rules to look for issues such as a redirect loop. When needed, you can log a ticket with us. Let us know the rules set is not working as expected, and provide a more detailed test example for us to take a further look. 
 +
 +==== Out of date database caused IP not blocked ====
 +A user setup the following at /​etc/​apache2/​conf.d/​userdata/​geoip.conf: ​
 +
 +  <​IfModule mod_geoip.c>​
 +  RewriteEngine on
 +  RewriteCond %{ENV:​GEOIP_COUNTRY_CODE} !^(GB|DK|US|IN)$
 +  RewriteRule (wp-login|xmlrpc)\.php$ - [F,L]
 +  </​IfModule>​
 +
 +Tested from an IP x.x.x.x (NG/​Nigeria/​-),​ it should be blocked but it didnot.
 +
 +Further analysis showing the above IP blongs to North Carolina, US in that downloaded MaxMind database and look like the record on that old database is incorrrect. If the database is not kept up to date, it will result in incorrect information.
 +
 +You can keep the database up to date from time to time manually by doing a direct download of the database, or you can use the [[https://​dev.maxmind.com/​geoip/​geoipupdate/​|geoipupdate -tool]], so your system automatically keeps the file up to date whenever MaxMind updates the records in the database.
  • Admin
  • Last modified: 2020/11/14 15:24
  • by Lisa Clarke