merge two location site to 1 location

Maxim Dounin mdounin at mdounin.ru
Fri Jan 7 20:35:13 MSK 2011


Hello!

On Fri, Jan 07, 2011 at 09:19:08PM +0700, Edho P Arief wrote:

> On Fri, Jan 7, 2011 at 9:00 PM, kevinew <nginx-forum at nginx.us> wrote:
> > Now i'll write two sections of location as follow:
> > location =/aaa{}
> > location =/BBB{}
> > But I want to write the two sections to one location?    eg. location
> > =/[aaa,BBB]{}  , but it's wrong, and does someone know how to write it?
> > Thanks in advance.
> >
> 
> if you want it to contain same thing, just create another file and
> include that file:
> 
> location = /aaa {
>   include blah;
> }
> location = /bbb {
>   include blah;
> }
> 
> alternatively someone may have made a tool to batch such job.
> 
> Or the slow (and therefore not recommended) way:
> 
> location ~ ^/(aaa|bbb)$ {
>   ...
> }

Note that regexp location is *NOT* the same thing.  Location given 
by regular expressions are quite different from "selecting 
matching location" perspective.

E.g. for request "/aaa" this configuration will select "location = 
/aaa":

    location ~ a { ... }
    location = /aaa { ... }
    location = /bbb { ... }

But this one will select "location ~ a" instead:

    location ~ a { ... }
    location ~ ^/(aaa|bbb)$ { ... }

Maxim Dounin



More information about the nginx mailing list