Reputation: 5943
This works fine by accessing http://localhost
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
But why doesn't it work when I try to access http://localhost/test with this configuration?
location /test {
root /usr/share/nginx/html;
index index.html index.htm;
}
Upvotes: 1
Views: 167
Reputation: 49812
Use the alias
directive:
location /test {
alias /usr/share/nginx/html;
index index.html index.htm;
}
With the root
directive, the value of the root and the URI are appended together to obtain the path to the file.
With the alias
directive, the value of the location is removed from the URI first, so /test/index.html
will be mapped to /usr/share/nginx/html/index.html
.
See this document for details.
Upvotes: 1