vhosts 或主机文件问题 - 转到本地主机"主页"(使用 WAMPServer)



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

我在我的.hosts文件中添加了以下行:

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

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

C:wampvhostslocal.conf

在我的虚拟主机文件(有很多现有的vhosts在那里),我已经添加了以下新的添加

<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主页。

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

C:wampvhosts文件夹现在是一个不存在的概念,您应该使用原始的wampbinapacheapachex.y.zconfextrahttpd-vhost.conf文件。然后取消在httpd.conf文件中包含该文件的注释,它接近httpd.conf文件的底部。

你也没有包括和说明Apache告诉它谁被允许访问这个网站。

在您创建的虚拟主机定义中也有一些错误。您应该为本地主机和您自己的新站点添加一个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:windowssystem32driversetchosts文件中为每个虚拟主机创建一个条目,以便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文件或该文件中包含的任何文件(如wampbinapacheapachex.y.zconfextrahttpd-vhosts.conf)中有错误,它将识别发现错误的行号。

最新更新