Reputation: 8374
I want to use nginx to host some static html which is located in different path on my pc, below is my configuration:
server {
listen 8080;
server_name localhost;
location /chatserver {
root /Users/xxxx/gitrepo/chatserver/public;
index index.html;
}
location /test {
root /Users/xxxx/test/test_site;
index index.html;
}
The file structure is:
Users
|-xxxx
|-gitrepo
| |-chatserver
| |-public
| |- index.html
|-test
|-test_site
|- index.html
But when I access: http://localhost:8080/chatserver
or http://localhost:8080/test
, nginx always responds 404 Not Found
.
If I access: http://localhost:8080/
, nginx will return the default nginx welcome page.
Why is my configuration not working?
Upvotes: 2
Views: 58
Reputation: 6027
I think you should use alias
instead of root
.
In your example the URL /chatserver/index.html
will search the /Users/xxxx/gitrepo/chatserver/public/chatserver/index.html
(note the "undesired" chatserver
after public
!). Check your nginx
's logfiles!
See documentation of root and documentation of alias.
Upvotes: 2