4 messages in ru.sysoev.nginxRe: Correct way to do redirect
FromSent OnAttachments
Chris SaveryAug 29, 2008 3:28 pm 
Igor SysoevAug 30, 2008 8:33 am 
Chris SaveryAug 30, 2008 9:10 am 
Igor SysoevAug 30, 2008 9:49 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Correct way to do redirectActions...
From:Igor Sysoev (is-G@public.gmane.org)
Date:Aug 30, 2008 8:33:32 am
List:ru.sysoev.nginx

On Sat, Aug 30, 2008 at 05:28:25AM +0700, Chris Savery wrote:

I'd like to do a geo based redirect. Users who initially hit my site would be given an IP round robin from the DNS servers. Then each node would test the ip and decide if it would be better to redirect to the closer node. Only doing this for index.php, eg.

http { ... geo $region { default NA; include georegions.conf; } ...

server { ... location ~ ^/index.php { if ($region = NA) --> what to write here to redirect to other IP? } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi_params; } } ... other servers...

First it's better to use more effective location:

- location ~ ^/index.php { + location = /index.php {

Or you may do it for "/" only:

location = / {

As to redirect, I think it's better to use something like this:

geo $region { default ""; include georegions.conf; }

server { location = /index.php {

if ($region) { rewrite ^ http://$region/index.php; }

fastcgi_pass 127.0.0.1:9000; ... }

The georegions.conf is site specific, i.e, for NA site:

x.x.x.x/x ""; # NA net x.x.x.x/x eu.domain.com; # EU net x.x.x.x/x as.domain.com; # AS net

for EU site:

x.x.x.x/x na.domain.com; # NA net x.x.x.x/x ""; # EU net x.x.x.x/x as.domain.com; # AS net