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
litespeed_wiki:config:geolocation [2017/10/02 14:18]
Eric Leu [Change your source IP by proxy]
litespeed_wiki:config:geolocation [2020/01/16 16:14] (current)
Lisa Clarke Redirected to new URL
Line 1: Line 1:
-====== How to enable GeoLocation ====== +~~REDIRECT>​litespeed_wiki:​cache:common:geoip-support~~
-Geolocation enables developers to enhance the user experience, making specific country'​s user to specific content or advertisements page. Showing pages more relevant to the location of the user. Admin user can further enhance the security through blocking a client based on country.  +
-===== Enabling GeoLocation is easy ===== +
-==== Install ==== +
-Install GeoIP database For CentOS user: +
-<code>yum install GeoIP-data</​code>​ +
-Install other modules: +
-<​code>​yum install GeoIP-devel zlib-devel</​code>​ +
- +
-==== Setup ==== +
-Check geo database: +
-<​code>​rpm -ql GeoIP</​code>​ +
-It may return database path as: +
-<​code>/​usr/​share/​GeoIP/​GeoIP.dat </​code>​ +
-In LSWS WebAdmin, configure the database location. ​ Configuration -> Server -> General ->​General settings:​->​ [[https://​www.litespeedtech.com/​docs/​webserver/​config/​general#​geolocationDB|IP to GeoLocation DB]] \\ +
-Enter the database path: +
-<​code>/​usr/​share/​GeoIP/​GeoIP.dat </​code>​ +
-Default DB Cache Type will be ''​MemoryCache''​\\ +
-{{:litespeed_wiki:​config:geo-4.png?​900|}} +
- +
-Setup rewrite rules from "Web Admin → Configurations → Your Virtual Hosts → Rewrite"​ to control the redirect: +
-<​code>​ +
-<​IfModule LiteSpeed>​ +
-  RewriteEngine on +
-  RewriteRule .* - [E=Cache-Control:​vary=%{ENV:​GEO_COUNTRY}] +
-</​IfModule>​ +
-</​code>​ +
-You can also refer to [[http://​dev.maxmind.com/​geoip/​legacy/​mod_geoip2/#​Redirecting_a_client_based_on_country | Maxmind]] page for 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 web IP and choose a country from three(USA, Germany, Netherlands). If you want more than three countries, then you need to register for 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 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 the System +
-  - Click Open proxy settings +
-  - Click on the LAN settings button. +
-  - On the Internet Properties window, click on 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. +
- +
-=== Check IP=== +
-  * You can check source IP via LiteSpeed defult php page <​nowiki>​http://​your_domain/​phpinfo.php</​nowiki>​. First, you need to set Admin -> Configurations -> Your Virtual Hosts -> General -> Enable GeoLocation Lookup set to ''​Yes''​ <​code>​ +
-_SERVER["​GEOIP_ADDR"​] +
-_SERVER["​GEOIP_COUNTRY_CODE"​] +
-_SERVER["​GEOIP_COUNTRY_NAME"​] +
-_SERVER["​GEOIP_CONTINENT_CODE"​] +
-</​code>​ +
-  * Or use online IP check, e.g. [[http://​whatismyipaddress.com/​| What is my IP]] +
- +
- +
-====Set Rewrite Rules==== +
-Web Admin -> Configurations -> Your Virtual Hosts -> Rewrite: +
-  * Set Rewrite to ''​Yes''​ +
-  * For testing purpose, we set Log Level to ''​9''​. +
-  * Add following rules to **Rewrite Rules** content <​code>​ +
-# Redirect two specific countries +
-RewriteCond %{ENV:​GEOIP_COUNTRY_CODE} ^(CA)$ +
-RewriteRule ^(.*)$ https://​en.wikipedia.org/​wiki/​Canada [R,L] +
-RewriteCond %{ENV:​GEOIP_COUNTRY_CODE} ^(EU)$ +
-RewriteRule ^(.*)$ https://​en.wikipedia.org/​wiki/​Europe [R,L] +
-</​code>​ +
-  +
-====Log==== +
-<​code>​ tail -f /​PATH_TO_LSWS/​log/​error.log </​code>​ +
-When you are using CA IP: +
-<​code>​ +
-[REWRITE] Rule: Match '/'​ with pattern '​^(.*)$',​ result: 2 +
-[REWRITE] Cond: Match '​CA'​ with pattern '​^(CA)$',​ result: 2 +
-[REWRITE] Source URI: '/'​ => Result URI: '​https://​en.wikipedia.org/​wiki/​Canada'​ +
-</​code>​ +
-When you are using Germany IP: +
-<​code>​ +
-[REWRITE] Rule: Match '/'​ with pattern '​^(.*)$',​ result: 2 +
-[REWRITE] Cond: Match '​EU'​ with pattern '​^(EU)$',​ result: 2 +
-[REWRITE] Source URI: '/'​ => Result URI: '​https://​en.wikipedia.org/​wiki/​Europe'​ +
-</​code>​ +
- +
-When you are using Netherlands IP: +
-<​code>​ +
-[REWRITE] Rule: Match '/'​ with pattern '​^(.*)$',​ result: 2 +
-[REWRITE] Cond: Match '​NL'​ with pattern '​^(CA)$',​ result: -1 +
-[REWRITE] Rule: Match '/'​ with pattern '​^(.*)$',​ result: 2 +
-[REWRITE] Cond: Match '​NL'​ with pattern '​^(EU)$',​ result: -1 +
-</​code>​ +
-  * ''​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 GeoIP database file(s) you are using. +
-  * If the GeoIP 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. GeoIP can only look up public IP addresses. +
- +
-==== More Information ==== +
-  * [[http://​www.ip2country.net/​ip2country/​country_code.html | IP Country Codes List:]] +
-    * UNITED STATES US +
-    * CHINA  ​       CN +
-    * GERMANY  ​       DE +
-  * Rewrite rule: Blocking a client based on country example:<​code>​SetEnvIf GEOIP_COUNTRY_CODE DE BlockCountry +
-Deny from env=BlockCountry</​code>​ +
- +
  • Admin
  • Last modified: 2017/10/02 14:18
  • by Eric Leu