Weird location choice

B.R. reallfqq-nginx at yahoo.fr
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 example.org/test returns KO.​

The location docs
<http://nginx.org/en/docs/http/ngx_http_core_module.html#location> 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: <http://mailman.nginx.org/pipermail/nginx/attachments/20151118/5be0c480/attachment.html>


More information about the nginx mailing list