Sep 162010
 

If you set

   location /mail/ {
       fastcgi_pass localhost:8888;
       ...
   }

and request “/mail” then nginx will return external redirect to “/mail/”.
If you do not want the redirect, then

   location = /mail {
       fastcgi_pass   localhost:8888;
       fastcgi_param  SCRIPT_FILENAME    $document_root/index.php;
       fastcgi_param  SCRIPT_NAME        /index.php;
       root           /var/www;
   }

   location /mail/ {
       fastcgi_pass   localhost:8888;
       fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
       fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
       fastcgi_index  index.php;
       root           /var/www;
   }

or set

server_name_in_redirect off;
Sep 162010
 

When you have many networks, which are located far apart and in different location. You want users to access the server closest to their network. town1 users when accessing the main server, the server will diredirect town1.example.com, and the town2’s users will be redirected to town2.example.com.

http {
     geo $geo {
          default      default;
          1.1.1.0/24   town1;
          1.1.2.0/24   town2;
          1.1.3.0/24   town3;
          ...
     }

     server {
          location / {
               rewrite ^(.*)$ http://$geo.example.com$1 permanent;
          }
     ...
     }
...
}