简体   繁体   中英

apache virtual hosts and document root

This might sound like a silly question but it's been bugging me for a while and I couldn't find any answer. I'm about to deploy a php+mysql web application to apache+linux production server. I set up a virtual host which points to the public folder of my main project directory. My question is:

-would it be different if I set public folder of my project directory as the default apache web root, instead of setting a seperate virtual host?

-should I restrict access to, or disable default web root since I'm not using it. If so, how?

thanks in advance.

Hope you have solved your problem. By the way I am posting answer here to help server administrator in future. So in future is any server admin has this type of question, they can refer to this answer.

There is no need to set default web root for this case. According to the Apache documentation the first virtual host entry will be taken if any match not found in subsequent entry. Refer to the following virtual host entry

NameVirtualHost *

<VirtualHost *>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /home/example/public_html
    ErrorLog /home/example/error.log
    CustomLog /home/example/access.log combined
</VirtualHost>

<VirtualHost *>
    ServerName www.example2.com
    ServerAlias example2.com
    DocumentRoot /home/example2/public_html
    ErrorLog /home/example2/error.log
    CustomLog /home/example2/access.log combined
</VirtualHost>

There is no need to disable default web root. Apache will automatically pic the first entry as default web root if no match found.

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