简体   繁体   中英

Apache VirtualHost configure

After I configured virtual host, my apache document root changed to the virtual host's document root, I just want to know why.

here is my httpd-vhosts.conf:

<VirtualHost *:80> 
   ServerName myapp.zend 
   DocumentRoot /opt/lampp/htdocs/php_zend_projects/myapp
   <Directory /opt/lampp/htdocs/php_zend_projects/myapp/public> 
      DirectoryIndex index.php 
      AllowOverride All 
      Order allow,deny 
      Allow from all 
      <IfModule mod_authz_core.c> 
         Require all granted 
      </IfModule> 
   </Directory> 
</VirtualHost>

After I restart apache server, localhost page changed to index of /opt/lampp/htdocs/php_zend_projects/myapp ,

http://gwjyhs.com/t6/702/1556725814x2728329017.png

but it is supposed to be xampp's default page like this:

http://gwjyhs.com/t6/702/1556726269x2728278877.png

If you enable vhosts you have to add an entry that looks like:

<VirtualHost *:80>
    DocumentRoot "F:/Dev/xampp/htdocs"
    ServerName localhost
</VirtualHost>

Note: change path to whatever is appropriate for you.

Restart webserver and it should work as before.

Reasoning behind this can be found in a comment on top of the httpd-vhosts.conf :

The first VirtualHost section is used for all requests that do not match a ##ServerName or ##ServerAlias in any block.

That means when you type in localhost it fallbacks to your myapp.zend vhost because it is (probably) the first virtualhost section.

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