Apache通配符子域到尾目录

我试图按照如何使子目录尾部特定的目录,所以例如我去http://sub.mydomain.com ,它应该把我的/var/www/sub的根。 http://randomdir.mydomain.com应该带我到/var/www/randomdir

我在SF上听了很多答案,但没有任何帮助。 基本上我做了一个通配符logging*.mydomain.com几天前,现在我已经在/etc/apache2/sites-enabled/mydomain.com.conf其中包含这个添加一个虚拟主机:

 <VirtualHost *:80> ServerName mydomain.com ServerAlias www.mydomain.com DocumentRoot /var/www/ </VirtualHost> <VirtualHost *:80> ServerName cake.mydomain.com ServerAlias *.mydomain.com DocumentRoot /var/www/%1 </VirtualHost> 

但是,当重新启动apache2,我得到这个返回:

 Warning: DocumentRoot [/var/www/%1] does not exist apache2: Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xxx for ServerName ... waiting Warning: DocumentRoot [/var/www/%1] does not exist apache2: Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xxx for ServerName 

我如何设法创build通配符子域名,指向基于名前缀的目录?

DocumentRoot /var/www/%1指令更改为VirtualDocumentRoot /var/www/%1

这个文件, dynamicconfiguration大容量虚拟主机似乎涵盖了你正在尝试做什么。

覆盖VirtualDocumentRoot指令的区域在mod_vhost_alias文档页面中有更详细的介绍,您可能会特别感兴趣。