try_files and a nested location regexp

Edho Arief me at myconan.net
Thu Oct 16 11:12:49 UTC 2014


On Thu, Oct 16, 2014 at 8:09 PM, igorb <nginx-forum at nginx.us> wrote:
> I tried to add explicit alias to the regexp location:
>
> server {
>         listen 8080 default_server;
>         root /usr/share/nginx/html;
>         autoindex on;
>
>         location /x/ {
>                 alias /test/;
>         }
>
>         location ~ ^/x/(test.*)$ {
>                 alias /test/$1;
>                 try_files $uri =404;
>         }
> }
>
> However that still gives 404 for localhost/x/test.html . Does that mean that
> try_files cannot be used at all in a regexp location defined with an alias,
> it only works if the location uses the root directive?
>

Why don't just use the alias in try_files?

    try_files /test/$1 =404;



More information about the nginx mailing list