Nginx geoip redirect based on country codes but exclude googlebot
Rainer Duffner
rainer at ultra-secure.de
Wed Nov 17 21:52:29 MSK 2010
Am 17.11.2010 um 13:55 schrieb st1905:
> Hello,
>
> I want to redirect people to specific pages on a website according to
> their country but i dont want to redirect googlebot or other spiders,
> how can i do this with nginx ?
>
> I have done redirection with php earlier but havent been able to
> exclude
> googlebot.
>
> As i read from maxmind website, on apache its done like this
>
> [code]
> GeoIPEnable On
> GeoIPDBFile /path/to/GeoIP.dat
>
> # Redirect one country
> RewriteEngine on
> RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
> RewriteRule ^(.*)$ http://www.canada.com$1 [L]
>
> # Redirect multiple countries to a single page
> RewriteEngine on
> RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|US|MX)$
> RewriteRule ^(.*)$ http://www.northamerica.com$1 [L]
> [/code]
>
>
> It still does not have any info to remove googlebot from redirection.
We did it like this (not for google - you have to find their ip-space)
http {
keepalive_timeout 65;
geoip_country /usr/local/etc/geo/GeoIP.dat ;
# these are the GeoIP exceptions for your site
geo $mygeo {
default 0;
bla/19 1;
blu/16 1;
}
then, in the server block:
location / {
include proxy-lcb-lt.conf;
if ($geoip_country_code = "US") {
proxy_pass http://prod;
}
# these are the exceptions, defined in nginx.conf:
if ($mygeo = "1") {
proxy_pass http://prod;
}
}
Hope this helps.
Rainer
More information about the nginx
mailing list