php - In Apache Server,does making the virtualhost enabled mean the 'Mainhost' is disabled?
I'm configging my apache server. In httpd.conf, I set the DocumentRoot as below:
And I set the directory node as below:
<Directory "D:/phpwwwroot"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory>
For this moment, I haven't enabled the virtual host. And I visit the url:
http://localhost:8080/, everything is ok.
Next, I tried to set the virtual host.I uncommented out the Virtual hosts. As below:
# Virtual hosts Include conf/extra/httpd-vhosts.conf
And my httpd-vhosts.conf is as below:
NameVirtualHost *:8080 <VirtualHost *:8080> ServerName www.testphp1.com DocumentRoot "D:\VirtualRoot" DirectoryIndex index.shtml index.html index.htm index.php <Directory "D:\VirtualRoot"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:8080> ServerName www.testphp2.com DocumentRoot "D:\VirtualRoot1" DirectoryIndex index.shtml index.html index.htm index.php <Directory "D:\VirtualRoot1"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> </VirtualHost>
And I also edit the hosts file to correct the mapping, you should know what I mean:
127.0.0.1 www.testphp1.com 127.0.0.1 www.testphp2.com
Next restart apache server, visit below urls:
Everything is ok. They are mapped to the right folder.
A new question raised, When I try to visit
http://localhost:8080/, it come to the first virtual host--www.testphp1.com. I means the page shows what
It seems that the "main host" doesn't work.
How does it happen? How to fix it
It's same situation when you're using IP to access server. It'll show first active website that uses this IP (
localhostis treated as IP here). You can fix it by defining main website first.
You need to add main host also such as: