Merge two location site to 1 location

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.

Posted at Nginx Forum:

On 7 Jan 2011 14h00 WET, [email protected] 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.

Yes but without exact matching like you have. AFAIK you need a
regex.

location ~* ^/(?:aaa|BBB)$ {

}
— appa

On Fri, Jan 7, 2011 at 9:00 PM, kevinew [email protected] 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)$ {

}

I had the idea to create a glob-like syntax which expands the
expression automatically upon loading config but as I don’t have
enough C skill and apparently there’s already tool for that (and
deemed sufficient), it’s never got implemented.

On 7 Jan 2011 14h10 WET, [email protected] wrote:

Oops must be case sensitive since you stated AAA and bbb:

location ~* ^/(?:aaa|BBB)$ {
^^
Becomes:
location ~ ^/(?:aaa|BBB)$ {

}
— appa

Hi APPA, Thank you greatly! you are so helpful~ I’ll use your case
sensitive one.

Posted at Nginx Forum:

Hello!

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

include that file:
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 D.

It’s better to make a tool to batch such job. As you said there is
already tool for that, and are you convenient to share a copy for us?

Posted at Nginx Forum: