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
location
block will work and it’s perfectly valid. What’s wrong is when you start addinglocation
blocks. If you add a root to every location block then alocation
block that isn’t matched will have no root. Therefore, it is important that a root directive occur prior to yourlocation
blocks, 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 root
or alias
, and serve that file if it is found.
The problem with putting the root
inside /
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
location
block 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.