5
如何将staging.example.com/siteA
形式的URI映射到位于/var/www/siteA
的虚拟服务器?将URL路径映射到nginx中的服务器
主要限制是我不想为siteA创建一个子域。到目前为止,我所见过的nginx.conf的所有例子都依赖于有一个子域来完成映射。
感谢
如何将staging.example.com/siteA
形式的URI映射到位于/var/www/siteA
的虚拟服务器?将URL路径映射到nginx中的服务器
主要限制是我不想为siteA创建一个子域。到目前为止,我所见过的nginx.conf的所有例子都依赖于有一个子域来完成映射。
感谢
您可以使用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;
}