<div dir="ltr"><div>Hi everyone,</div><div><br></div><div>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)<br></div><div>do the following:</div><div><br></div><div>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</div><div><br></div><div>    - mkdir try_files_test && cd try_files_test</div><div>    - mkdir public blog-public client-body fastcgi uwsgi scgi</div><div>    - touch nginx.conf</div><div>    - echo "does not matter here" > public/index.html</div><div>    - echo "Blog" > blog-public/index.html</div><div><br></div><div>Put this content into the nginx.conf<br></div><div><br></div><div>## <nginx.conf> ##</div><div>pid "nginx.pid";<br><br>daemon off;<br>events {<br>    worker_connections 1024;<br>}<br>error_log /dev/stdout debug;<br><br>http {<br>    client_body_temp_path "client-body";<br>    fastcgi_temp_path "fastcgi";<br>    uwsgi_temp_path "uwsgi";<br>    scgi_temp_path "scgi";<br>    access_log /dev/stdout;<br>    rewrite_log on;<br><br>    root "public";<br>    server {<br>        listen 8080;<br><br>        location / {<br>            return 200 "Homepage\n";<br>        }<br><br>        location  /blog {<br>            root "blog-public";<br>            set $foo /;<br>            try_files $foo $foo/ $foo/index.html =404;<br>        }<br>    }<br>}<br></div><div>## </nginx.conf> ##</div><div><br></div><div>and start it with</div><div><br></div><div>    - nginx -p $PWD -c nginx.conf</div><div><br></div><div>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<br></div><div><br></div><div>    - curl -i <a href="http://localhost:8080/blog/">http://localhost:8080/blog/</a></div><div><br></div><div>If we change the try_files line inside /blog's location blog</div><div><br></div><div>    try_files $foo $foo/index.html =404;</div><div><br></div><div>by removing the $foo/ the curl request returns the intended "Blog".  Instead of putting in the $foo/ again, we just put // there, like this</div><div><br></div><div>    try_files $foo // $foo/index.html =404;</div><div><br></div><div>and we get "Homepage" for an /blog/ request again.</div><div><br></div><div>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.</div><div><br></div><div><br></div><div>Thanks in advance for your time and have a good weekend if you're reading this today.</div><div><br></div><div>Regards</div><div>Maik Beckmann<br></div></div>