在子域上configuration具有不同根文件夹的多个位置的nginx
我正在寻找服务的子域的子url和子域的目录到我的服务器上的两个不同的文件夹。 这里是我有和没有工作的简单的设置…
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; } } 在这个例子中,去test.example.com/将索引文件放在/web/test.example.com/www
并去test.example.com/static将带来索引文件/web/test.example.com/static
 您需要使用alias指令来location /static : 
 server { index index.html; server_name test.example.com; root /web/test.example.com/www; location /static { alias /web/test.example.com/static; } } 
nginx维基比我能更好地解释根和别名之间的区别:
请注意,它可能看起来类似于root指令,但文档根目录不会改变,只是用于请求的文件系统path。 请求的位置部分在请求Nginx问题中被丢弃。
位置指令系统是
 就像你想要转发/var/www/static所有启动/static请求和你的数据一样 
所以一个简单的方法是将最后一个文件夹从完整path中分离出来
 完整path: /var/www/static 
 最后一个path: /static和第一个path: /var/www 
 location <lastPath> { root <FirstPath>; } 
因此,让我们看看你做错了什么,你的解决scheme是什么
你的错误:
 location /static { root /web/test.example.com/static; } 
您的解决scheme
 location /static { root /web/test.example.com; } 
 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; } }