我在本地Windows机器上的xampp上设置了3个vhost。 (见下面的配置)
每当我将浏览器定向到stage.local或host.local时,我都会被重定向到dev.local,这是我首先设置的vhost,但不应该是默认的vhost。
然而,当我转到host.local / index.php时,会显示正确的文件,不知何故,它只是被搞砸的根目录。 我不确定这是怎么可能的,或者如何解决这个问题。
配置似乎正确,这是完整的文件:
#
# Use name-based virtual hosting.
#
NameVirtualHost *
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
<VirtualHost *>
ServerAdmin webmaster@host.local
DocumentRoot "C:/xampp/htdocs/host.local/"
ServerName host.local
</VirtualHost>
<VirtualHost *>
ServerAdmin webmaster@stage.local
DocumentRoot "C:/xampp/htdocs/stage.local/"
ServerName stage.local
ErrorLog "logs/stage.local-error.log"
CustomLog "logs/stage.local-access.log" common
</VirtualHost>
<VirtualHost *>
ServerAdmin webmaster@dev.local
DocumentRoot "C:/xampp/htdocs/dev.local/"
ServerName dev.local
ErrorLog "logs/dev.local-error.log"
CustomLog "logs/dev.local-access.log" common
</VirtualHost>
httpd -S说:
*:* is a NameVirtualHost
default server host.local (C:/xampp/apache/conf/extra/httpd-vhosts.conf:29)
port * namevhost host.local (C:/xampp/apache/conf/extra/httpd-vhosts.conf:29)
port * namevhost stage.local (C:/xampp/apache/conf/extra/httpd-vhosts.conf:35)
port * namevhost dev.local (C:/xampp/apache/conf/extra/httpd-vhosts.conf:43)
(之后的一些事情)
我的hosts文件包含以下条目:
127.0.0.1 localhost
127.0.0.1 host.local
127.0.0.1 stage.local
127.0.0.1 dev.local
答案 0 :(得分:0)
对我而言,它正在发挥作用。您需要为例如: -
定义端口#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@host.local
DocumentRoot "C:/xampp/htdocs/host.local/"
ServerName host.local
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@stage.local
DocumentRoot "C:/xampp/htdocs/stage.local/"
ServerName stage.local
ErrorLog "logs/stage.local-error.log"
CustomLog "logs/stage.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dev.local
DocumentRoot "C:/xampp/htdocs/dev.local/"
ServerName dev.local
ErrorLog "logs/dev.local-error.log"
CustomLog "logs/dev.local-access.log" common
</VirtualHost>