Score:0

Difference between "location /" and Nginx default server block values

tg flag

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.

Score:1
us flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.