<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=KOI8-R" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Helvetica, Arial, sans-serif">Thank you Igor. <br>
<br>
I expected you would know the correct or optimal way to do this.<br>
After posting the question I did more reading and found out that
rewrite will redirect when the rule give http as start of the result.
That was what I didn't know before.<br>
<br>
After playing around I found that loading the smallest geo table I
could make from the country database (converted to continent regions)
pushed the footprint size of nginx up from about 4MB to over 11 MB. I
wasn't too happy with wasting so much memory just to lookup ips.š I'm
exploring now possible use of PowerDNS with geo backend to do
geo-direction at the DNS level. I'd be happier with using a database
lookup and saving memory even it means it's a bit slower since I only
do this mapping once per visit. <br>
<br>
I don't see any nginx module to do mysql queries or perhaps sqlite.
Something like that could work I think. I have mysql running anyway and
can't get away from having it swallow a chunk of memory. Oh well, I
wasn't running my own dns servers but probably should and in that case
it would be little overhead to do it there. Still tinkering with how to
do this in a light memory environment. <br>
<br>
Chris :)<br>
</font><br>
Igor Sysoev wrote:
<blockquote cite="mid:20080830153355.GA70849@rambler-co.ru" type="cite">
  <pre wrap="">On Sat, Aug 30, 2008 at 05:28:25AM +0700, Chris Savery wrote:

  </pre>
  <blockquote type="cite">
    <pre wrap="">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)
--&gt; what to write here to redirect to other IP?
         }
       location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include 
fastcgi_params; }
   }
... other servers...
    </pre>
  </blockquote>
  <pre wrap=""><!---->
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  ^   <a class="moz-txt-link-freetext" href="http://$region/index.php">http://$region/index.php</a>;
             }

             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


  </pre>
</blockquote>
</body>
</html>