我正在尝试在我的机器上设置我从本地另一个开发人员收到的移动应用程序,这是一个基于 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 主页。
任何人都可以建议我的设置中可能有什么问题吗?
最佳答案
C:\wamp\vhosts
文件夹现在是一个废弃的概念,您应该使用原来的 wamp\bin\apache\apachex.y.z\conf\extra\httpd-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:\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 - 虚拟主机或主机文件问题 - 转到本地主机 'homepage'(使用 WAMPServer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25309881/