这是我的/etc/httpd/conf.d
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/成功地将我重定向到适当的网站。访问http://192.168.1.4/也会将我重定向到同一个网站,而不是我期待看到的索引。此外,访问http://test.dev-some-random-string.192.168.1.4.xip.io/也将重定向我到同一个网站。
我如何配置它,以便当我尝试访问test.dev.192.168.1.4.xip.io时,我将在我正在编码的页面中结束,而访问192.168.1.4.xip.io将显示主页。
目前,我正在使用一个带有网络桥接适配器的虚拟盒中运行的centos 6。这是我的/etc/httpd/conf/httpd.conf。
发布于 2015-06-07 08:39:56
如果只定义一个虚拟主机,那么对httpd的所有请求都将由该虚拟主机处理,无论它们是否与ServerName或ServerAlias匹配,因为第一个虚拟主机也是默认的虚拟主机。在Apache “基于名称的虚拟主机支持”文档中搜索“默认虚拟主机”。
还要注意的是,一旦定义了任何虚拟主机,默认的ServerName就会消失,如果您仍然想要使用它,就必须定义一个新的vhost来重新创建它。请参阅上面链接中的“主主机离开”。
所以,尝试定义一个默认的虚拟主机,它可以非常简单
<VirtualHost *:80>
DocumentRoot /var/www/html
</VirtualHost>并确保它出现在配置中的所有其他虚拟主机之前。然后,任何与其他虚拟主机不匹配的请求都将由该虚拟主机处理。
发布于 2015-06-07 08:18:47
您需要为您想要显示的每个网站定义一个VirtualHost;即使192.168.1.4是主要站点,也需要定义一个定义"ServerAlias 192.168.1.4“的VirtualHost。如果只有一个VirtualHost,则将始终重定向到在ServerAlias中定义的站点。
https://serverfault.com/questions/697181
复制相似问题