Apache 2.4 VirtualHost ServerName被忽略

时间:2016-06-02 16:46:17

标签: apache amazon-ec2 virtualhost httpd.conf

在Amazon EC2上,我有以下配置:

<VirtualHost *:80>
    ServerName   a.example.com
    ServerRoot   /var/www/a.example.com
    DocumentRoot html
</VirtualHost>

<VirtualHost *:80>
    ServerName   b.example.com
    ServerRoot   /var/www/b.example.com
    DocumentRoot html
</VirtualHost>

<VirtualHost *:80>
    ServerName   c.example.com
    ServerRoot   /var/www/c.example.com
    DocumentRoot html
</VirtualHost>

问题是,尽管上述配置是正确的,但所有对3个域名中的任何一个的请求都被定向,就像请求转到c.example.com一样 - 好像ServerName值只是被忽略了。

有人在这里看到问题吗?

2 个答案:

答案 0 :(得分:1)

ServerRoot仅允许server config Context,而不是VirtualHost

  

如果您尝试在其他地方使用它,您将收到配置错误   将阻止服务器处理该请求   上下文正确,或将使服务器完全无法运行 -   即,服务器甚至不会启动。

答案 1 :(得分:0)

我发现的问题是我的Apache2构建:

Server version: Apache/2.4.18 (Amazon)
Server built:   Mar  7 2016 22:32:11

未正确处理DocumentRoot参数。

在DocumentRoot配置定义here,它说

  

如果目录路径不是绝对路径,则假定它是   相对于ServerRoot。

嗯,这显然被忽略了,因为如果我更改DocumentRoot值如下:

<VirtualHost *:80>
    ServerName   b.example.com
    ServerRoot   /var/www/b.example.com
    DocumentRoot html
</VirtualHost>

对此:

<VirtualHost *:80>
    ServerName   b.example.com
    ServerRoot   /var/www/b.example.com
    DocumentRoot /var/www/b.example.com/html   #<-- updated
</VirtualHost>

然后配置工作。我没有经过测试,看看这是一个核心Apache版本的问题,或者如果它与亚马逊版本有关,无论哪种方式,我希望这个答案可以帮助某人。

相关问题