I think I need to improve my reading skills.
Here’s the Nginx pitfalls article.
I can’t seem to understand a simple sentence (bolded) in the following paragraph:
This works. Putting root inside of a
locationblock will work and it’s perfectly valid. What’s wrong is when you start adding
locationblocks. If you add a root to every location block then a
locationblock that isn’t matched will have no root. Therefore, it is important that a root directive occur prior to your
locationblocks, which can then override this directive if they need to. Let’s look at a good configuration.
From what I understand, when a request is received by Nginx, after resolving the server block, it will try to match the URI with the location blocks’
location_match (the path to match to). If a URI matches, it will look inside the file location which is defined by
alias, and serve that file if it is found.
The problem with putting the
/ location block, instead of putting it in the server block, is that there will be no default root path for all requests. This means that all location blocks will need to have a
root or else, it will have no default root path to fall back to and thus the file can’t be found.
Here’s the confusing (to me) sentence again:
If you add a root to every location block then a
locationblock that isn’t matched will have no root.
If the request is for
/hello and I only have a location block that only matches exactly to
/ola, what does it mean that the location block
/ola which is the “location block that is not matched” will have no root?
It is confusing to me because the phrase before that is “If you add a root to every location block ”. How can a location block with a root suddenly loses its root when it is not matched?
Thank you for reading this; I think I’m overthinking this and I get the gist of the message. But yet, it feels that I am misreading the paragraph.