Weird location choice

B.R. reallfqq-nginx at
Wed Nov 18 20:18:51 UTC 2015

WIth the following configuration:
server {
    listen      80;
    listen      [::]:80;

    location / {
        location ~* "^/[[:alnum:]]+$" {
            default_type text/plain;
            return 200 "KO";

    location ~* "^/test" {
        default_type text/plain;
        return 200 "OK";

​I noticed that calling returns KO.​

The location docs
<> say the
longest prefix match ('/') is remembered then regex are checked. Since the
'test' regex is on the same level, you would expect higher precedence for
it compared to the embedded 'alnum' one, which is one level deeper.

If secondary-level regex locations have the same priority as others, you
are basically doomed trying to prioritize regex locations between each
others using prefix locations at an upper-level.

​Where am I wrong?​
*B. R.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list