A
A
appplemac2012-04-20 12:38:13
Nginx
appplemac, 2012-04-20 12:38:13

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;
}

In this configuration, for a request like mysite.com/files, I get 404 Not Found.
Tell me what am I doing wrong?
Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Peretyatko, 2012-04-20
@appplemac

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 question

Ask a Question

731 491 924 answers to any question