Generating redirects to internal named locations

Dave Hayes dave at jetcafe.org
Mon Aug 8 03:57:53 UTC 2011


Alexandr Gomoliako <zzz at zzz.org.ua> writes:
> On 8/8/11, Dave Hayes <dave at jetcafe.org> wrote:
>> Greetings nginx gurus. :) Is there a better way to generate a redirect
>> to a named location than this?
>> location ~ \.pl$ {
>> try_files /this_should_never_exist @perl;
>> }
> Another way is to use error_page in conjunction with return.
> But in this case you should just replace try_files with your named
> location's config.

If I have several location blocks in a server block, and I want to use
just one location block that has my fastcgi definitions for perl (hence
@perl), are you recommending I just duplicate all the configuration
in each location block that needs to redirect to perl? 

Saying this another way, by example:

 location @perl {
    # 20 lines of fast cgi defs
 }
   
 location /realm_a { 
   auth_basic "realm_a";
   location ~ \.pl$ { 
      try_files /does_not_exist @perl;
   }
 }

 location /realm_b { 
   auth_basic "realm_b";
   location ~ \.pl$ { 
      try_files /does_not_exist @perl;
   }
 }

 location /realm_c { 
   auth_basic "realm_c";
   location ~ \.pl$ { 
      try_files /does_not_exist @perl;
   }
 }

Your recommendation is to do this:
   
 location /realm_a { 
   auth_basic "realm_a";
   location ~ \.pl$ { 
      # 20 lines of fast cgi defs
   }
 }

 location /realm_b { 
   auth_basic "realm_b";
   location ~ \.pl$ { 
      # 20 lines of fast cgi defs
   }
 }

 location /realm_c { 
   auth_basic "realm_c";
   location ~ \.pl$ { 
      # 20 lines of fast cgi defs
   }
 }

Did I get that right? :)
-- 
Dave Hayes - Consultant - Altadena CA, USA - dave at jetcafe.org 
>>> The opinions expressed above are entirely my own <<<

A "No" uttered from deepest conviction is better and greater
than a "Yes" merely uttered to please, or what is worse, to
avoid trouble.                              -- Mahatma Ghandi




More information about the nginx mailing list