我的Apacheconfiguration有什么问题?

我正在运行一个AWS设置,该设置目前由指向单个EC2实例的ELB组成。 该实例正在运行Ubuntu 12.04.2和Apache 2.22.2。 过去我在服务器上设置了几个子域名。 今天我正在设置另外一个,但是我正在靠墙敲打我的头,试图弄清楚我错过了什么。 我敢肯定,这是我忽视或不太对的一小步。

我的DNSlogging使用Route 53进行设置。我login到AWS控制台并为我的服务器添加了一个新的CNAMElogging。 我们将其称为samael.example.com 。 它看起来像这样:

 samael.example.com. 3600 IN CNAME web-pool-xxxxxxxxxx.us-east-1.elb.amazonaws.com. 

这似乎工作得很好,因为指向我的浏览器sameael.example.com带来了默认的VirtualHost。

所以,我现在要做的就是创build另一个VirtualHostconfiguration文件, 对吧

 mkdir /http/www/samael.example.com touch /httpd/www/samael.example.com/index.html cd /etc/apache2/sites-available sudo cp dav.example.com samael.example.com sudo sed -i 's/dav.example.com/samael.example.com/g' samael.example.com cd ../sites-enabled sudo ln -s ../sites-available/samael.example.com sudo apachectl restart 

那应该是 ? 但是当我将浏览器指向samael.example.com ,它仍然指向默认的VirtualHost。 我跳过了什么步骤?

cat samael.example.com

 <VirtualHost *:80> ServerName samael.example.com ServerAdmin webmaster@localhost DocumentRoot /httpd/www/samael.example.com <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /httpd/www/samael.example.com> Options FollowSymLinks AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/samael.example.com-error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/samael.example.com-access.log combined 

编辑:

根据评论中的要求:

 sudo apache2ctl -S VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server dav.example.com (/etc/apache2/sites-enabled/dav.example.com:1) port 80 namevhost dav.example.com (/etc/apache2/sites-enabled/dav.example.com:1) port 80 namevhost dev.example.com (/etc/apache2/sites-enabled/dev.example.com:1) port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com:1) port 80 namevhost new.example.com (/etc/apache2/sites-enabled/new.example.com:1) port 80 namevhost samael.example.com (/etc/apache2/sites-enabled/samael.example.com:1) port 80 namevhost stage.example.com (/etc/apache2/sites-enabled/stage.example.com:1) port 80 namevhost test.example.com (/etc/apache2/sites-enabled/test.example.com:1) Syntax OK 

这个输出对我来说有点令人费解。 我希望默认是example.com而不是dav.example.comexample.com的configuration文件在其中定义了ServerAlias *

有可能是你的虚拟主机configuration文件没有被apache看到,无论是缺lessinclude指令,还是缺less权限。

确保在你的主configuration文件中有一个类似的指令

 Include /etc/apache2/sites-enabled/* 

如果在条件块中,比如<IfDefine VHOSTS> ,确保条件评估为真(例如,通过确保指定了正确的定义或正确的模块被加载)。

另外,确保运行apache的用户(通常是apache)有权读取文件并枚举启用站点的目录。 具体而言,它需要在启用站点的目录上读取和执行,并读取启用站点的所有configuration文件。

根据你的编辑,你所拥有的ServerAlias *指令很可能是令人困惑的事情。 这不是指定默认虚拟主机的方式。 只有在没有其他虚拟主机匹配(ServerAlias或ServerName)的情况下才使用默认虚拟主机,并且只是按照字母顺序加载的第一个虚拟主机。 这就是dav.example.com主机最有可能被选中的方式。 为了克服这个问题,通常将目标虚拟主机configuration文件命名为00_default_vhost.conf。

匹配也是在读取文件的顺序中完成的。 因此,任何不是dav.example.comdev.example.com网站都将通过example.com与通配符别名进行匹配。