【发布时间】:2016-04-03 18:56:53
【问题描述】:
我遇到了关于 Apache 2.4 的问题,它是 VirtualHost 配置。
我有一个子域sub.example.com 和一个子域static.sub.example.com。我尝试分配不同的 DocumentRoots,但我在下面的配置只会导致 /var/www/html/。
<VirtualHost *:80>
ServerName sub.example.com
DocumentRoot /var/www/html/
</VirtualHost>
<VirtualHost *:80>
ServerName static.sub.example.com
DocumentRoot /var/www/html/static/
</VirtualHost>
我做错了什么?
附加信息:上面的配置在一个文件/etc/apache2/sites-available/000-default.conf 中,当然是启用的(默认情况下)。所有其他配置都是不变的默认值。服务器在 Ubuntu 14.04 上运行。
我找到了this solution,但不幸的是它对我不起作用。
更新:apachectl -S 的输出:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80 is a NameVirtualHost
default server sub.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost sub.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost static.sub.example.com (/etc/apache2/sites-enabled/000-default.conf:6)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
// Some more lines that are not related I think
更新:寻找解决方案的附加信息:
我在我的网络服务器前运行了一个反向代理。从反向代理的000-default.conf 中提取(也是 Apache 2.4):
ProxyPass / http://webserver/ nocanon
ProxyPassReverse / http://webserver/
【问题讨论】:
-
还有其他虚拟主机在工作吗?您似乎根本没有启用虚拟主机功能。
-
我想是的,是的。我用
apachectl -S的输出更新了我的帖子。 -
确保您的文件包含在 httpd.conf 的 Include 指令中(通常位于文件的底部)
-
是的。如果我更改 VirtualHost 条目的顺序,我可以看到站点 static.sub.example.com 的内容。但是在 static.sub.example.com 和 sub.example.com 上。
-
好的,您的 ServerName 指令似乎被忽略了,或者您没有像在 ServerName 指令中那样在 url 中使用确切的名称,并且 apache 使用遇到的第一个虚拟主机,因为这是在没有匹配项时默认使用的。确保您的地址没有拼写错误。
标签: apache