try_files and a nested location regexp

Francis Daly francis at daoine.org
Thu Oct 16 11:28:17 UTC 2014


On Thu, Oct 16, 2014 at 07:09:44AM -0400, igorb wrote:

Hi there,

>         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?

try_files puts its "file" argument after $document_root, and looks for
a file on the filesystem with that combined name.

alias-with-regex sets $document_root to the value given.

So if you want try_files and alias-with-regex, you want something like

  try_files "" =404

But that specific use of try_files is probably not very useful, since
it is mostly the same as having no try_files at all -- I guess it is a
simplified version of what you really want, so it is useful as an example.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list