Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Using try_files or not, does not seem to make a real difference

$
0
0
This is just an understanding question, everything works, but i'm not quite sure why.

My basic setup is a folder /var/www/test inside there is a "index.html" and another folder called "folder" and inside this folder another "index.html".

=== Config ===
server_name mydomain.com;
root /var/www/test;
location / {
index index.html;
try_files $uri $uri/ =404;
}
=== /Config ====

I read the error debug logs, and this is what happens for various requests.

request: mydomain.com/test
try_files tries serving test as a file > fails, which it should
try_files tries opening the directory test/ > OK
index index.html triggers and nginx serves test/index.html to the client > OK

Now i remove the try_files line form the config and reload nginx. Nginx skips the try_files event but it still has the same result:
Nginx can't open the file test, so it automatically redirects to test/ (WHY? i did not tell it to) and then index triggers again and serves the index.html.

So does it make any difference in my case using try_files or not? From what i read, it's seems to be the "cleaner" solution?
Maybe it's the default behavior of nginx to serve a request first as a file and than as a folder?

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>