I'm looking to serve the root url of a subdomain and directory of a subdomain to two different folders on my server. Here is the simple set-up that I have and is not working...
server {
index index.html index.htm;
server_name test.example.com;
location / {
root /web/test.example.com/www;
}
location /static {
root /web/test.example.com/static;
}
}
In this example going to test.example.com/
would bring the index file in /web/test.example.com/www
and going to test.example.com/static
would bring the index file in /web/test.example.com/static
You need to use the
alias
directive forlocation /static
:The nginx wiki explains the difference between root and alias better than I can:
http://nginx.org/r/root
The Location directive system is
Like you want to forward all request which start
/static
and your data present in/var/www/static
So a simple method is separated last folder from full path , that means
Full path :
/var/www/static
Last Path :
/static
and First path :/var/www
So lets see what you did mistake and what is your solutions
Your Mistake :
Your Solutions :