INFO
I have below directories structure:
. ├── fruits │ └── index.html ├── index.html ├── styles.css and the content of my /etc/nginx/nginx.conf file is:
http { include mime.types; server { listen 8090; root /srv/www/mysite; location /fruits { root /srv/www/mysite; } } } events {} The nginx version is 1.24.0 (Ubuntu).
QUESTION
In modern nginx versions is there any difference in defining location with and without trailing slashes? For example: location /fruits { ... } vs location /fruits/ { ... } I tried both of them and no matter which I choose, the result is always the same:
http://localhost:8090/fruitsservesfruits/index.html, which is OKhttp://localhost:8090/fruitsaladresults in 404 Not Found
I have mentioned the second example because I have searched through some threads here on SO and some other places, and the information contained there is different comparing to what I have observed on my nginx version. For example the answer with 25 upvotes (its first paragraph) from this thread (2014): https://serverfault.com/a/607731 - product-production and fruits-fruitsalad follows the same pattern, but my results and the result described by the user in mentioned thread are different.
I have also noticed that even if I choose the definition without trailing slash (location /fruits) nginx somehow adds the trailing slash, so in my web browser when I hit Enter button after typing http://locahost:8090:fruits this address is redirected to http://locahost:8090:fruits/. curl also shows that redirection 301 has taken place, so this is another thing that confuses me and makes me thinking that nowadays in nginx these trailing slashes aren't important at all.
http://localhost:8090/fruitsaladresults in 404 Not Found - no wonder since you don't have thefruitsaladfile (or directory) under your web server root. The answer you referring already mentions the relevant documentation part regarding..._passdirectives used as a location content handler; however, locations that used static content handler behaves the same way, as I described here. From my point of view, you should not use locations without trailing slash (unless you really need to for some very specific reason).