启用虚拟主机后,Wamp目录无法正常工作

时间:2016-10-26 05:06:44

标签: php apache wamp virtualhost

我已经为wamp中的新应用程序创建了一个虚拟主机。

在我的httpd.conf

# Virtual hosts
Include conf/extra/httpd-vhosts.conf  //<--- Removed #

在我httpd.vhosts.conf我添加了一个新主机

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot "C:/wamp/www/myapp"
  ServerName myapp.local
  ServerAlias 127.0.0.1
  SetEnv APPLICATION_ENV "development"
  <Directory "C:/wamp/www/myapp/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
  </Directory>
</VirtualHost>

虚拟主机工作正常。但问题是我在没有虚拟主机的情况下运行的其他应用程序无效。

当我打开http://localhost/fistapp/时,显示

Forbidden 403

You don't have permission to access / on this server.

1 个答案:

答案 0 :(得分:1)

创建虚拟主机定义后,Apache基本上会忽略httpd.conf文件中定义的localhost域,因此您还必须在httpd-vhosts.conf文件中定义locahost。因此,您的httpd-vhosts.conf文件应如下所示:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot c:/wamp/www
    <Directory  "c:/wamp/www/">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

# made some amendments to this VH as well
<VirtualHost *:80>
  DocumentRoot "C:/wamp/www/myapp"
  ServerName myapp.local
  # not sure why this is here ServerAlias 127.0.0.1
  ServerAlias www.myapp.local

  SetEnv APPLICATION_ENV "development"

  <Directory "C:/wamp/www/myapp">
    Options +Indexes +FollowSymLinks +MultiViews
    AllowOverride all
    Require local
  </Directory>
</VirtualHost>

别忘了修改C:\windows\system32\drivers\etc\hosts文件以添加您的新域名

127.0.0.1  localhost
::1 localhost

127.0.0.1 myapp.local
::1 myapp.local