GIT – The mod_geoip2 module embeds GeoIP database lookups into the Apache web server. It is only capable of looking up the IP of a client that connects to the web server, as opposed to looking up arbitrary addresses.

Installation

You can download mod_geoip2 from our server. See the INSTALL file in the tarball for installation details or view

http://www.gocit.vn/bai-viet/installing-mod_geoip-apache/

Usage

The README file in the tarball provides more details on what directives are available with mod_geoip2, but here are some examples.

GeoIP configuration directives can be placed in either an .htaccess file or in the main server config.

Redirecting a client based on country

This example allows you to redirect a client based on the country code that GeoIP sets.

GeoIPEnable On

GeoIPDBFile /path/to/GeoIP.dat

# Redirect one country

RewriteEngine on

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$

RewriteRule ^(.*)$ http://www.canada.com$1 [R,L]

# Redirect multiple countries to a single page

RewriteEngine on

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|US|MX)$

RewriteRule ^(.*)$ http://www.northamerica.com$1 [R,L]

Blocking a client based on country

This example allows you to block clients based on the country code that GeoIP sets.

GeoIPEnable On

GeoIPDBFile /path/to/GeoIP.dat

SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry

SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry

# … place more countries here

Deny from env=BlockCountry

Allowing clients based on country

This example allows you to only allows clients from specific countries.

GeoIPEnable On

GeoIPDBFile /path/to/GeoIP.dat

SetEnvIf GEOIP_COUNTRY_CODE US AllowCountry

SetEnvIf GEOIP_COUNTRY_CODE CA AllowCountry

SetEnvIf GEOIP_COUNTRY_CODE MX AllowCountry

# … place more countries here

Deny from all

Allow from env=AllowCountry

Print Friendly

Comments

comments

Bài viết liên quan