Apache on Windows localhost and virtualhosts

谁说我不能喝 提交于 2019-12-11 19:45:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!