Using try_files or not, does not seem to make a real difference
January 10, 2014 05:46PM
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?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 201
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