Answer the question
In order to leave comments, you need to log in
Nginx location directive not working?
Welcome all.
I just can't figure out how location directives work in Nginx.
I need a page from /var/www to be returned for a request like mysite.com/ , and at the same time that for a request mysite.com/files I can view files from /media/web with an auto-index.
I tried to do this with the following parts of the config:
location / {
root /var/www;
index index.html;
}
location /files {
root /media/web;
autoindex on;
}
Answer the question
In order to leave comments, you need to log in
The problem here is not in the location, but in the fact that you did not fully understand how the root directive works:
When requesting mysite.com/files, nginx tries to give out the /media/web/files folder, but you don’t have it, hence 404.
From the documentation: “The path to the file is formed by simply adding the URI to the value of the root directive. If the URI needs to be changed, the alias directive should be used.
That is, you just need to replace root with alias
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question