Welcome! Log In Create A New Profile

Advanced

try_files doubleslash mystery

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

I'm putting some hours into better understanding how Nginx works. While
doing so I came across something that I can't explain nor find anything
about in web-searches. To reproduce on your Linux machine (I'm using Arch,
if you want to check how nginx was build on their Website)
do the following:

With your normal user account (we are never root in this), enter /tmp or a
place in your home folder where you like to experiment. Execute these
commands

- mkdir try_files_test && cd try_files_test
- mkdir public blog-public client-body fastcgi uwsgi scgi
- touch nginx.conf
- echo "does not matter here" > public/index.html
- echo "Blog" > blog-public/index.html

Put this content into the nginx.conf

## <nginx.conf> ##
pid "nginx.pid";

daemon off;
events {
worker_connections 1024;
}
error_log /dev/stdout debug;

http {
client_body_temp_path "client-body";
fastcgi_temp_path "fastcgi";
uwsgi_temp_path "uwsgi";
scgi_temp_path "scgi";
access_log /dev/stdout;
rewrite_log on;

root "public";
server {
listen 8080;

location / {
return 200 "Homepage\n";
}

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

and start it with

- nginx -p $PWD -c nginx.conf

When requesting / via curl, we get "Hompage" as expected. However, if we
request /blog/ we get "Homepage as well. For the convinence, here to curl
command

- curl -i http://localhost:8080/blog/

If we change the try_files line inside /blog's location blog

try_files $foo $foo/index.html =404;

by removing the $foo/ the curl request returns the intended "Blog".
Instead of putting in the $foo/ again, we just put // there, like this

try_files $foo // $foo/index.html =404;

and we get "Homepage" for an /blog/ request again.

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.


Thanks in advance for your time and have a good weekend if you're reading
this today.

Regards
Maik Beckmann
_______________________________________________
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: 66
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready