httpd – 虚拟主机转到同一个网站

这里是我的/etc/httpd/conf.d/test.conf

NameVirtualHost *:80 <VirtualHost *:80> ServerName test.dev ServerAlias test.dev.*.xip.io DocumentRoot /var/www/html/user/test/web ErrorLog "/var/www/html/user/test/app/logs/httpd_error.log" CustomLog "/var/www/html/user/test/app/logs/httpd_access.log" combined <Directory "/var/www/html/user/test/web"> # AllowOverride All # Deprecated # Order Allow,Deny # Deprecated # Options All # Allow from all # Deprecated # Require all granted # << New way of doing it Options +FollowSymlinks +Indexes AllowOverride all </Directory> </VirtualHost> 

访问http://test.dev.192.168.1.4.xip.io/成功将我redirect到正确的网站。 访问http://192.168.1.4/也redirect到同一个网站,而不是我期待看到的索引。 另外,访问http://test.dev-some-random-string.192.168.1.4.xip.io/也会将我redirect到同一个网站。

我如何configuration这个,所以当我尝试访问test.dev.192.168.1.4.xip.io时 ,我将在页面编码,而访问192.168.1.4.xip.io将显示我的主页。

我目前正在使用一个虚拟框中运行的一个centos 6与桥接适配器的networking。 这是我的/etc/httpd/conf/httpd.conf。

http://pastebin.com/iFBin5Lu

如果仅定义一个虚拟主机,则所有对httpd的请求都将由该虚拟主机提供,无论它们是否与ServerName或ServerAlias匹配,因为第一个虚拟主机也是默认虚拟主机。 在Apache “基于名称的虚拟主机支持”文档中search“默认虚拟主机”。

还要注意,一旦你定义了任何虚拟主机,默认的ServerName就会消失,如果你还想使用它,你必须定义一个新的虚拟主机来重新创build它。 在上面的链接看插图“主人走开”。

所以,尝试定义一个默认的虚拟主机,可以像这样简单

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

并确保它在configuration中的所有其他虚拟主机之前 。 然后,任何与其他虚拟主机不匹配的请求将由该服务器提供。

您需要为每个要显示的网页定义一个VirtualHost; 即使192.168.1.4是主要的,你也需要定义一个VirtualHost,其中定义了“ServerAlias 192.168.1.4”。 如果只有一个VirtualHost,您将被redirect到ServerAlias中定义的站点。