0

What is the point of defining location / { } since, if I understand correctly this will match all potential URIs and "lose" any battle against a location with a more specific URI ? My reasonning is you can just put all default values directly into the server block instead of defining a location / { }.

Hence if I am correct, this serves no purpose :

server {
   root /www/html;
   location / {
      root /www/html;
   }

}

PS: I am quite new to nginx so feel free to tell me if I could phrase things better to make the question more useful/discoverable.

1 Answer 1

1

You are correct, your specific example serves no purpose. But there are a lot of nginx directives that don't work on server-level

for example:

server {
    proxy_pass http://localhost:8080;
}

^ this does not work.
v this does.

server {
    location / {
        proxy_pass http://localhost:8080;
    }
}

Server-level directives are default values. There are directives that work only in server-level, there are directives work only on location-level.

Its two fundamentally different things, it's just that your example has the same consequences.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.