Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
litespeed_wiki:config:geolocation [2017/10/02 15:58] Lisa Clarke |
litespeed_wiki:config:geolocation [2020/01/16 16:14] (current) Lisa Clarke Redirected to new URL |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Enabling GeoLocation ====== | + | ~~REDIRECT>litespeed_wiki:cache:common:geoip-support~~ |
- | Geolocation enables developers to enhance the user experience. Content and advertising may be customized for a specific user's country, showing pages more relevant to the location of the user. Admins can further enhance a site's security by blocking a client based on country. | + | |
- | ===== How to Enable ===== | + | |
- | Enabling GeoIP is easy. | + | |
- | ==== Install ==== | + | |
- | Install GeoIP database for CentOS users: | + | |
- | <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 a database path similar to: | + | |
- | <code>/usr/share/GeoIP/GeoIP.dat </code> | + | |
- | In LSWS WebAdmin, configure the database location. Navigate to **Configuration > Server > General > General settings > [[https://www.litespeedtech.com/docs/webserver/config/general#geolocationDB|IP to GeoLocation DB]]** \\ | + | |
- | Enter **DB File Path**: | + | |
- | <code>/usr/share/GeoIP/GeoIP.dat </code> | + | |
- | Set **DB Cache Type** to ''MemoryCache''\\ | + | |
- | {{:litespeed_wiki:config:geo-4.png?900|}} | + | |
- | + | ||
- | Navigate to **Web Admin > Configurations > Your Virtual Hosts > Rewrite** to add rewrite rules that will control the redirect: | + | |
- | <code> | + | |
- | <IfModule LiteSpeed> | + | |
- | RewriteEngine on | + | |
- | RewriteRule .* - [E=Cache-Control:vary=%{ENV:GEO_COUNTRY}] | + | |
- | </IfModule> | + | |
- | </code> | + | |
- | Refer to [[http://dev.maxmind.com/geoip/legacy/mod_geoip2/#Redirecting_a_client_based_on_country | Maxmind]] 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. | + | |
- | + | ||
- | ==== Check Correct IP is Set==== | + | |
- | * You can check source IP via LiteSpeed default php page ''<nowiki>http://your_domain/phpinfo.php</nowiki>''. First, you need to set **Admin > Configurations > Your Virtual Hosts > General > Enable GeoLocation Lookup** 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]] | + | |
- | * Or ''ipinfo.io'' online service, which will return json format: <code>curl ipinfo.io/153.232.58.88 | + | |
- | >>> | + | |
- | { | + | |
- | "ip": "153.232.58.88", | + | |
- | "hostname": "88.58.232.153.ap.dti.ne.jp", | + | |
- | "city": "Tokyo", | + | |
- | "region": "Tokyo", | + | |
- | "country": "JP", | + | |
- | "loc": "35.6850,139.7514", | + | |
- | "org": "AS4713 NTT Communications Corporation", | + | |
- | "postal": "102-0082" | + | |
- | }</code> | + | |
- | + | ||
- | ==== Check DB by lookup command==== | + | |
- | Use ''geoiplookup''/''geoiplookup6'' command to verify GeoData is working: <code>geoiplookup /usr/share/GeoIP/GeoIP.dat 62.26.0.0 | + | |
- | >> GeoIP Country Edition: DE, Germany | + | |
- | geoiplookup /usr/share/GeoIP/GeoIP.dat 210.212.193.192 | + | |
- | >> GeoIP Country Edition: IN, India | + | |
- | </code> | + | |
- | + | ||
- | + | ||
- | ====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: <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:]] | + | |
- | * Rewrite rule: Blocking a client based on country example:<code>SetEnvIf GEOIP_COUNTRY_CODE DE BlockCountry | + | |
- | Deny from env=BlockCountry</code> | + | |
- | + |