我试图让两个网站在同一台服务器上使用不同的IP地址。 我已经build立了一个虚拟IP,并设置了虚拟主机。 添加界面后,我重新启动了networking,添加虚拟主机后重新启动了apache。
但是,第二个站点的默认IP地址仍在parsing中。 我究竟做错了什么?
服务器
CentOS版本6.3(el6.x86_64 GNU / Linux)
IFCONFIG
eth0 Link encap:Ethernet inet addr:12.34.567.89 Bcast:12.34.567.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 eth0:1 Link encap:Ethernet inet addr:12.34.567.90 Bcast:12.34.567.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
HTTPconfiguration
NameVirtualHost 12.34.567.89 NameVirtualHost 12.34.567.90 <VirtualHost 12.34.567.89> DocumentRoot /var/www/html ServerName website1.com </VirtualHost> <VirtualHost 12.34.567.90> DocumentRoot /var/www/html ServerName website2.com </VirtualHost>
PING
# ping website2.com PING website2.com (12.34.567.89) 56(84) bytes of data.
如果我浏览12.34.567.90,它指向错误的网站:website1.com而不是website2.com
任何帮助将不胜感激,因为我已经在这几个星期。
注意:特定的IP地址已被简化,并删除了不相关的内容。
# ping website2.com PING website2.com (12.34.567.89) 56(84) bytes of data.
主机名parsing的内容不受您的Apacheconfiguration的影响,而仅受您的域名的DNSlogging的影响。
根据ping ,website2.comparsing为12.34.567.89,但唯一的(因此默认)为12.34.567.89的虚拟主机是website1.com,所以你登陆网站1。
因此,您应该检查您的DNSloggingconfiguration是否正确。
如果您有两台服务器分开的IP地址,则不应使用NameVirtualHost 。 该指令专门用于在同一个IP地址上有多个站点。 所以删除这两个指令。
另外,在您发布的configuration中,两个网站都有相同的DocumentRoot,这意味着它们将提供相同的内容。 但也许这是你混淆的东西之一?
我认为NameVirtualHost指令正在引入基于名称的虚拟主机,尝试删除它们。 确保你有一个合适的听指令
Listen 80
看看他们也把端口放在虚拟主机定义的文档 ,所以试试
Listen 80 <VirtualHost 12.34.567.89:80> DocumentRoot /var/www/html ServerName website1.com </VirtualHost> <VirtualHost 12.34.567.90:80> DocumentRoot /var/www/html ServerName website2.com </VirtualHost>
是在所有的IP上列出的Apache?
运行RHEL / CentOS
netstat -ntlp |grep httpd
或Debian / Ubuntu
netstat -ntlp |grep apache2