如何添加虚拟主机来为(工作)CNAME请求提供服务?

在AWS EC2机器上,在我的/etc/httpd/conf/httpd.conf文件中,我有这个服务器configuration:

 NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin [email protected] ServerName www.example.com DocumentRoot /var/www/html <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/html/zf2-tutorial/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

这在处理“www.example.com”stream量方面做得很好,当我请求“www.example.com/Workstream”时,我得到了位于/var/www/html/Workstream的应用程序。

所以,感觉自己很好,我决定我想成为幻想,并有Web服务器path“ 工作stream .example.com”stream量到/var/www/html/Workstream 工作stream (遵循Apache VirtualHost文档和示例 )。

所以我得到了CNAME别名到相关的Alogging – 完成,工作,很好。 然后我把目光放在httpd.conf文件上,在现有的<VirtualHost>后面加上:

 <VirtualHost *:80> ServerAdmin [email protected] ServerName workstream.example.com DocumentRoot /var/www/html/Workstream <Directory /> Options FollowSymLinks AllowOverride All </Directory> </VirtualHost> 

我保存了编辑,然后重新启动apache( sudo /usr/sbin/apachectl restart – 不知道为什么我的apache不是其他人的),并指出浏览器在“workstream.example.com”和… /var/www/html 。 重新启动后返回这个警告:

[警告] 默认 VirtualHost在80端口重叠,第一个优先

我是这样的linux noob它是痛苦的。 我究竟做错了什么? 我正在编辑正确的httpd.conf(使用find / -xdev 2>/dev/null -name "httpd.conf"我看到/opt/railo/sys/httpd.conf有另一个httpd.conf)? ServerName是否需要对应我没有设置的东西? 我的语法不正确?


sudo /usr/sbin/apachectl -S是:

 VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server www.example.com (/etc/httpd/conf/httpd.conf:1005) port 80 namevhost www.example.com (/etc/httpd/conf/httpd.conf:1005) port 80 namevhost workstream.example.com (/etc/httpd/conf/httpd.conf:1020) Syntax OK 

您的configuration中是否有NameVirtualHost *:80 (请参阅“ NameVirtualHost指令 ”)指令? 如果不是,那么将被视为基于IP的虚拟主机,忽略浏览器发送的Host头。

NameVirtualHost *:80指令应该是您需要使错误消失。 Apachectl拿起来,所以我的怀疑是Apache没有得到正确的重新加载。 …不是那个人…但是你有没有尝试重新启动

另一种方法是杀死ps -ef列出的所有httpd pids并开始?

如果所有的请求被一个虚拟主机caching,也许你缺less默认的虚拟主机http://httpd.apache.org/docs/2.2/vhosts/examples.html

 <VirtualHost _default_:80> DocumentRoot /var/www/html </VirtualHost>