vhosts或hosts文件问题 - 转到localhost'主页'(使用WAMPServer)

时间:2014-08-14 13:56:53

标签: wamp virtualhost wampserver vhosts hosts

我正在尝试在我的机器上设置一个我从本地另一个开发人员收到的移动应用程序,这是一个基于cordova的移动应用程序,基本上是html5 / javascript等。

我已将以下行添加到我的.hosts文件中:

127.0.0.1 app.myapps.local
127.0.0.1 localhost # existing line has always been there #

在我的WAMP版本中,我的虚拟主机位于以下目录中:

C:\wamp\vhosts\local.conf

在我的虚拟主机文件中(那里有很多现有的虚拟主机)我添加了以下添加

<VirtualHost *:80>
  ServerAdmin me@website.com
  DocumentRoot "c:/wwwroot/app/App/www/app.html"
  ServerName app.myapps.local
<Directory "c:/wwwroot/app/App/www/app.html">
    Options +Indexes
    AllowOverride All
</Directory>
  ErrorLog "c:/wwwroot/app/log/error.log"
  CustomLog "c:/wwwroot/app/log/access.log" common
  LogLevel debug
  SetEnv MANGO_ENVIRONMENT ME
</VirtualHost>

我已经重新启动了apache并刷新了dns,但由于某些原因,每次我在浏览器中加载app.myapps.local时,我都会看到默认的WAMPSERVER主页。

有人可以建议我的设置可能出错吗?

1 个答案:

答案 0 :(得分:2)

C:\wamp\vhosts文件夹现在已经不存在了,您应该使用原始的wamp\bin\apache\apachex.y.z\conf\extra\httpd-vhost.conf文件。然后在httpd.conf文件中取消注释该文件的包含,它位于httpd.conf文件的底部附近。

此外,您还未向Apache提供说明并告知其允许谁访问此站点。

您创建的虚拟主机定义中也存在一些错误。您应该为localhost和您自己的新站点添加VHOST定义。 DocumentRoot "c:/wwwroot/app/App/www/app.html"也是错误的,它应该只识别文件夹而不包含页面名称,同样是<Directory...>参数。

# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "C:/wamp/www">
        AllowOverride All
        #If APACHE2.4
        #   Require local

        #If APACHE2.2
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1 localhost ::1 
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin me@website.com
    DocumentRoot "c:/wwwroot/app/App/www"
    ServerName app.myapps.local

    <Directory "c:/wwwroot/app/App/www">
        AllowOverride All
        Options +Indexes
        #If APACHE2.4
        #   Require local

        #If APACHE2.2
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1 localhost ::1 
    </Directory>

    ErrorLog "c:/wwwroot/app/log/error.log"
    CustomLog "c:/wwwroot/app/log/access.log" common
    LogLevel debug
    SetEnv MANGO_ENVIRONMENT ME

    # as you have moved the Apache logs it may also be a good idea
    # to move the php error log as well.
    php_value error_log "c:/wwwroot/app/log/php_error.log"
</VirtualHost>

现在,您必须在C:\windows\system32\drivers\etc\hosts文件中为每个虚拟主机创建一个条目,以便Windows知道您在ServerName参数中创建的域的位置,就像您所做的那样,但它是一个最好添加IPV4地址127.0.0.1和IPV6地址::1

#The first 2 line should already be in here
127.0.0.1 localhost
::1 localhost

127.0.0.1 app.myapps.local
::1 app.myapps.local

完成此更改后,您可以从命令窗口重新加载Windows DNS缓存,这也必须使用Run as Administrator菜单选项启动。

net stop dnscache
net start dnscache

然后您应该准备重新加载Apache以获取所有这些更改。

如果遇到问题,请记住Apache在实际打开自己的错误日志之前写入Windows事件日志。如果您在httpd.conf文件或该文件中包含的任何文件(例如wamp\bin\apache\apachex.y.z\conf\extra\httpd-vhosts.conf)中有错误,它将识别发现错误的行号。

相关问题