【问题标题】:vhosts or hosts file issue - going to localhost 'homepage' (using WAMPServer)vhosts 或 hosts 文件问题 - 转到本地主机“主页”(使用 WAMPServer)
【发布时间】:2014-10-08 05:06:41
【问题描述】:

我正在尝试在我的机器上设置我从另一个开发人员本地收到的移动应用程序,这是一个基于科尔多瓦的移动应用程序,基本上是 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 主页。

谁能建议我的设置有什么问题?

【问题讨论】:

    标签: wamp virtualhost wampserver vhosts hosts


    【解决方案1】:

    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" 也是错误的,它应该只识别文件夹而不包括页面名称,同上&lt;Directory...&gt; 参数。

    # 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)中有错误,它将识别发现错误的行号。

    【讨论】:

    • 我只能在wamp\bin\apache\apachex.y.z\conf\extra` 看到httpd-vhosts.conf 文件(注意's')没有httpd-vhost.conf 文件。
    • @OmarTariq 较小的拼写错误已更正。它实际上被称为httpd-vhosts.conf 如果这是这个答案的唯一问题,我做得很好
    猜你喜欢
    • 2019-03-02
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 2019-06-30
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 2020-08-05
    相关资源
    最近更新 更多