同一个子域可以有多个虚拟文档根目录吗?

Possible to have more than one virtual document root for the same subdomain?

我正在设置一个开发服务器,我想知道是否可以设置多个虚拟主机作为使用虚拟文档根目录的同一子域的后备?

澄清一下,假设我有这个虚拟主机,它基本上允许 ex1.somedomain.com 下的动态子域,文件夹名称成为子域的名称。这一切都很好。

<VirtualHost [ip address here]:80>
   UseCanonicalName off
   VirtualDocumentRoot /home/firstuser/www/%1/public_html/
   ServerAlias *.ex1.somedomain.com

   <Directory /home/firstuser/www/*/public_html/>
      AllowOverride all
   </Directory>

   AddHandler php5-fcgi .php
   Action php5-fcgi /php5-fcgi
   Alias /php5-fcgi /home/firstuser/www/php5-fcgi
   FastCgiExternalServer /home/firstuser/www/php5-fcgi -socket /tmp/php5-fpm-firstuser.sock -pass-header Authorization -idle-timeout 600
</VirtualHost>

就是说.. 出于与组织和权限相关的原因,我想我可以在它之后添加另一个虚拟主机,如果该文件夹不存在于第一个虚拟文档根目录中,它将作为后备。例如,如果 /home/firstuser/www/test 不存在,它将尝试下一个虚拟主机并查看 /home/seconduser/www/test 是否存在,如果存在则提供该内容......但它似乎不起作用。

<VirtualHost [ip address here]:80>
   UseCanonicalName off
   VirtualDocumentRoot /home/seconduser/www/%1/public_html/
   ServerAlias *.ex1.somedomain.com

   <Directory /home/seconduser/www/*/public_html/>
      AllowOverride all
   </Directory>

   AddHandler php5-fcgi .php
   Action php5-fcgi /php5-fcgi
   Alias /php5-fcgi /home/seconduser/www/php5-fcgi
   FastCgiExternalServer /home/seconduser/www/php5-fcgi -socket /tmp/php5-fpm-seconduser.sock -pass-header Authorization -idle-timeout 600
</VirtualHost>

这样配置的正确方法是什么?

没有内置支持在文件不存在时从一个虚拟主机跳到另一个虚拟主机,但 mod_rewrite 手册中有一些方法向您展示了之前如何在文件系统中四处寻找将 URI 更改为文件系统映射。

http://httpd.apache.org/docs/2.4/rewrite/remapping.html#multipledirs

RewriteEngine on

#   first try to find it in dir1/...
#   ...and if found stop and be happy:
RewriteCond         "%{DOCUMENT_ROOT}/dir1/%{REQUEST_URI}"  -f
RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/dir1/"  [L]

#   second try to find it in dir2/...
#   ...and if found stop and be happy:
RewriteCond         "%{DOCUMENT_ROOT}/dir2/%{REQUEST_URI}"  -f
RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/dir2/"  [L]

#   else go on for other Alias or ScriptAlias directives,
#   etc.
RewriteRule   "^"  "-"  [PT]