Francis Daly
August 17, 2019 02:06PM
On Sat, Aug 17, 2019 at 10:23:46AM +0200, Maik Beckmann via nginx wrote:

Hi there,

> location /blog {
> root "blog-public";
> set $foo /;
> try_files $foo $foo/ $foo/index.html =404;
> }

> When requesting / via curl, we get "Hompage" as expected. However, if we
> request /blog/ we get "Homepage as well.

> Now my Question: Is there something about double slash as the $uri that
> causes nginx to do a magical internal redirect? I don't understand.

It is not "double slash". It is "the argument to try files (before
variable expansion) ends in slash".

https://nginx.org/r/try_files

"""
The path to a file is constructed from the file parameter according to
the root and alias directives. It is possible to check directory’s
existence by specifying a slash at the end of a name, e.g. “$uri/”.
"""

$foo does not end in slash, so try_files looks for a file of that
(expanded) name, and fails to find it.

$foo/ does end in slash, so try_files looks for a directory of that
(expanded) name, and finds it and serves it (which involves a
subrequest/internal redirect).

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

try_files doubleslash mystery

Maik Beckmann via nginx August 17, 2019 04:26AM

Re: try_files doubleslash mystery

Francis Daly August 17, 2019 02:06PM

Re: try_files doubleslash mystery

Maik Beckmann via nginx August 18, 2019 05:42AM

Re: try_files doubleslash mystery

Francis Daly August 20, 2019 09:24AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 155
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready