简体   繁体   中英

Adding virtual host changes DocumentRoot in httpd.conf

In my httpd.conf there is,

DocumentRoot "/var/www/html"

When I add an index.php in this directory and give http://localhost , it works OK.

But now I add a virtual host in 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.

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 :

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. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM