2013-10-30 112 views
5

如何将staging.example.com/siteA形式的URI映射到位于/var/www/siteA的虚拟服务器?将URL路径映射到nginx中的服务器

主要限制是我不想为siteA创建一个子域。到目前为止,我所见过的nginx.conf的所有例子都依赖于有一个子域来完成映射。

感谢

回答

12

您可以使用root directive一个location块中,像这样:

server { 
    server_name staging.example.com; 
    root /some/other/location; 
    location /siteA/ { 
     root /var/www/; 
    } 
} 

然后http://staging.example.com/foo.txt/some/other/location/foo.txt,而http://staging.example.com/siteA/foo.txt/var/www/siteA/foo.txt

请注意,siteA目录仍然存在于文件系统中。如果您要http://staging.example.com/siteA/foo.txt指向/var/www/foo.txt,则必须使用alias directive

location /siteA/ { 
    alias /var/www; 
} 
相关问题