[英]Adding virtual host changes DocumentRoot in httpd.conf
In my httpd.conf there is, 在我的httpd.conf中,
DocumentRoot "/var/www/html"
When I add an index.php in this directory and give http://localhost
, it works OK. 当我在此目录中添加index.php并提供
http://localhost
,它工作正常。
But now I add a virtual host in httpd.conf, 但是现在我在httpd.conf中添加了一个虚拟主机,
<VirtualHost *:80>
DocumentRoot /home/eric/Devel/Web
ServerName web
</VirtualHost>
When I give http://localhost
, the document root is the one in web, /home/eric/Devel/Web and the index.php in there is the server.This is what I do not understand. 当我提供
http://localhost
,文档根目录是Web中的目录,/ home / eric / Devel / Web,其中的index.php是服务器,这是我不明白的。
Thanks. 谢谢。
You're using name-based virtual hosts, in which case the virtual host named first in the configuration becomes the default. 您正在使用基于名称的虚拟主机,在这种情况下,配置中第一个命名的虚拟主机将成为默认主机。 See the remark in the httpd docs :
请参阅httpd文档中的注释:
Main host goes away
主主机消失
If you are adding virtual hosts to an existing web server, you must also create a block for the existing host.
如果要将虚拟主机添加到现有Web服务器,则还必须为现有主机创建一个块。 The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot.
此虚拟主机中包含的ServerName和DocumentRoot应该与全局ServerName和DocumentRoot相同。 List this virtual host first in the configuration file so that it will act as the default host.
首先在配置文件中列出该虚拟主机,以使其充当默认主机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.