Geoip redirect but exclude a specific directory

Hello,

I`m using the method described in here to redirect people with specific
ips to locations

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;
}
}

Problem is the administrator of the site is from one of the countries
that gets redirected so he cant access the administration section of the
site instead he gets redirected to another place.

How can i exclude the directory “admin” from the above geoip redirection
?

Thanks for any suggestion.

Posted at Nginx Forum:

Hello!

On Mon, Nov 22, 2010 at 03:34:27PM -0500, st1905 wrote:

[…]

Problem is the administrator of the site is from one of the countries
that gets redirected so he cant access the administration section of the
site instead he gets redirected to another place.

How can i exclude the directory “admin” from the above geoip redirection
?

location / {
…do whatever you want here…
}

location /admin/ {
…do whatever you want here…
}

See here for more details:

http://wiki.nginx.org/HttpCoreModule#location

Maxim D.

Tried

location ~ ^/admin/.+.php$ {

fastcgi_pass 127.0.0.1:9000;
root /var/www/vhosts/domain.com/httpdocs;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
break;
}

if ($mygeo = “1”) {
break;

}

if ($geoip_country_code = “DE”) {
rewrite ^(.*)$ http://de.domain.com permanent;

                                           }

Still someone with ip from germany cant access the admin section, what
i`m doing wrong here ?

Thanks.

Posted at Nginx Forum:

Rainer D. Wrote:

being from Germany?
nginx Info Page
Thank you for the reply, the ip is dynamic and yes its marked as coming
from germany.

Posted at Nginx Forum:

Am 23.11.2010 um 18:27 schrieb st1905:

Still someone with ip from germany cant access the admin section, what
i`m doing wrong here ?

And the IP is in the GeoIP-datablock marked as being from Germany?

Download the csv-version of the database and look it up yourself.

Rainer

I solved this by adding following rewrite rule just above the if
statements for the geoip redirection

if ($request_uri ~* ^/admin)
{
break;
}

That solved the issue, now when someone from germany goes to site root
they will still be redirected but if they go to admin section of the
site, it wont redirect, thanks a lot Rainer and Maxim.

Posted at Nginx Forum: