问题
So here is my problem, I'm running wamp 2.2 on a windows 8.1 machine.
Now, after the install, localhost works fine. When I go to create a virtual host, after setting up the httpd.conf file, if I were to create for example :
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test/"
ServerName test.local
</VirtualHost>
Well this just overrides my localhost. First of all, test.local does not work, and if I were to use localhost it takes me to c:/wamp/www/test/
Anybody have a solution for this ?
PS : I have been setting up my hosts file for windows correctly (addind: 127.0.0.1 test.local), and my 80 port is free (no skype and antivirus turned off).
EDIT: I've also tried with a different port (8080) and the problem continues.
The message I get on my browser is : "Google chrome could not find the website"
回答1:
If you have virtual hosts set up and you still want to access the localhost webroot, you need to add a vhost for your localhost first
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.
http://httpd.apache.org/docs/2.0/vhosts/name-based.html
Example (untested):
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:\wamp/www
</VirtualHost>
<VirtualHost *:80>
ServerName otherdomain.local
DocumentRoot C:\wamp/www/otherdomain
</VirtualHost>
回答2:
Try this:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test"
ServerName test.local
ServerAlias test.local
<directory "c:/wamp/www/test">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Require local
</directory>
</VirtualHost>
来源:https://stackoverflow.com/questions/20348215/apache-on-windows-localhost-and-virtualhosts