location ^~ modifier

B.R. reallfqq-nginx at yahoo.fr
Tue Dec 8 17:33:52 UTC 2015


The location
<http://nginx.org/en/docs/http/ngx_http_core_module.html#location>
documentation states the following:
*A location can either be defined by a prefix string, or by a regular
expression.*

Thus, ~ and ~* being regex modifiers, the rest is considered as being
classified as 'prefix.
That means the following is a 'prefix' location block:
location /whatever/ {
}

That said, this block will match the /whatever/ string anywhere in the URI
string, not only at its start.

As a consequence, to me, the meaning of 'prefix' was not tied to the
location of the matched string in the URI, but rather a definition more
like 'matching a string in the URI'.

Without any modifier, a prefix location will be sensitive to the presence
of regex locations, while with the ^~ modifier it also won't match the same
cases.
That modifier actually have 2 consequences, instead of only the first being
documented. My brain hurts...

Note that if you remove the capability of the default (without any
modifier) location to match the string anywhere in the URI (thus becoming
'prefix' *per se*), you do not have any other means to match a string
regardless of its position in the URI than regex ones... which are
discouraged from being used (see recent answer from Maxim on a similar
topic).

​Where is the exit of the maze again?​
---
*B. R.*

On Tue, Dec 8, 2015 at 9:40 AM, Francis Daly <francis at daoine.org> wrote:

> On Mon, Dec 07, 2015 at 10:08:40PM +0100, B.R. wrote:
>
> Hi there,
>
> > Does the ^~ location modifier finds a matching string at the start of an
> > URI?
>
> Yes.
>
> > I naively thought it was just a variant of the classic prefix search,
>
> Yes.
>
> > without any constraint on the placement of the matched string in an URI.
>
> No.
>
> > Is there a simple way of matching the longest prefix location anywhere in
> > an URI, discarding any regex location at the same level?
>
> "prefix" means "at the start".
>
> I'm not sure what you're asking.
>
> The first regex location that matches is used (with caveats). So if you
> have a regex location which is just your desired string, that is first in
> the config file, then it will be used ahead of any other regex locations
> that might have been used.
>
>         f
> --
> Francis Daly        francis at daoine.org
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20151208/62bff3c1/attachment.html>


More information about the nginx mailing list