在 WAMP 上安装虚拟主机后无法访问默认 localhost
Posted
技术标签:
【中文标题】在 WAMP 上安装虚拟主机后无法访问默认 localhost【英文标题】:Default localhost can't be accessed after installing virtual hosts on WAMP 【发布时间】:2015-01-17 08:31:43 【问题描述】:对于我一整天都在努力解决的问题,我真的很感激……我使用 WAMP 在本地安装了 WordPress,一切正常。我在 C:/wamp/www 中创建了一个文件夹,并将其命名为 wordpress。 我只能通过在浏览器的 URL 上键入 localhost 来访问 localhost,并且我访问了键入 localhost/wordpress/ 但是当我决定安装另一个 wordpress 网站时遇到问题的站点。我在 www 中创建了第二个文件夹,将其命名为 joanaweb 并按照本教程的步骤操作:http://www.marolinedesign.com/tutorials/how-to-install-more-than-one-wordpress-site-on-your-local-wamp-server/ PLUS 我删除了位于 httpd.conf 上的 Include conf/extra/httpd-vhosts.conf 之前的 #,这在教程。 在此之后,第一个网站像以前一样访问,而第二个网站通过键入 joanaweb....但是我无法再访问 localhost :( 我只收到一个 403 错误。在这个网站 http://www.apptools.com/phptools/virtualhost.php 在文章末尾我发现一个解决方案,但它对我不起作用:/ 他们建议使用:
<VirtualHost 127.0.0.1>
DocumentRoot C:\Apache\htdocs
ServerName localhost
</VirtualHost>
由于我的 htdocs 位于另一个文件夹中,因此我在 httpd-vhosts.conf 上使用了此代码
<VirtualHost *:80>
DocumentRoot "C:/wamp/bin/apache/apache2.4.9/htdocs/"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost.log"
CustomLog "logs/localhost.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/joanaweb"
ServerName joanaweb
ServerAlias joanaweb
ErrorLog "logs/joanaweb.log"
CustomLog "logs/joanaweb.log" common
</VirtualHost>
我做错了什么??
这也是我的 hosts 文件中的所有代码(在 cmets 之后):
127.0.0.1 localhost
::1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost localhost
127.0.0.1 localhost wordpress
127.0.0.1 localhost joanaweb
127.0.0.1 localhost lifestylepro
127.0.0.1 localhost xxxxxTranslations
这是 httpd-vhosts.conf 中的代码:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/wordpress"
ServerName wordpress
ServerAlias wordpress
<Directory "C:/wamp/www/wordpress">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
ErrorLog "logs/wordpress.log"
CustomLog "logs/wordpress.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/joanaweb"
ServerName joanaweb
ServerAlias joanaweb
<Directory "C:/wamp/www/joanaweb">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
ErrorLog "logs/joanaweb.log"
CustomLog "logs/joanaweb.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/lifestylepro"
ServerName lifestylepro
ServerAlias lifestylepro
<Directory "C:/wamp/www/lifestylepro">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
ErrorLog "logs/lifestylepro.log"
CustomLog "logs/lifestylepro.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/xxxxxTranslations"
ServerName xxxxxTranslations
ServerAlias www.xxxxxTranslations
<Directory "C:/wamp/www/xxxxxTranslations">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
ErrorLog "logs/xxxxxTranslations.log"
CustomLog "logs/xxxxxTranslations.log" common
</VirtualHost>
【问题讨论】:
你在C:\Windows\System32\drivers\etc
中编辑过你的hosts文件吗?
是的,我已经为第二个网站添加了这行代码... 127.0.0.1 joanaweb
您的姓名和别名应以 TLD 结尾(.com
或 .dev
等)。
我在某处读到它们是可选的,但也许这不正确。谢谢你的回答,我马上试试
它没有用:/我想我必须“关闭”其他网站,当我需要访问 localhost 时只允许 www/wordpress,谢谢 :)
【参考方案1】:
好的,首先摆脱 httpd-vhosts.conf
的这 2 部分,这 2 位只是 Apache 发布的示例代码以帮助您入门,与 WAMPServer 无关,因为它们指向 WAMPServer 不使用的位置。
所以删除这两个定义
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
然后我们来您的虚拟主机定义,因为您使用的是 Apache v2.4.x,我将删除 Apache 版本检查并仅使用 Apache 2.4 语法以使其更易于理解。
# 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
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/wordpress"
ServerName wordpress
ServerAlias wordpress
<Directory "C:/wamp/www/wordpress">
AllowOverride All
Require local
</Directory>
ErrorLog "logs/wordpress.log"
CustomLog "logs/wordpress.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/joanaweb"
ServerName joanaweb
ServerAlias joanaweb
<Directory "C:/wamp/www/joanaweb">
AllowOverride All
Require local
</Directory>
ErrorLog "logs/joanaweb.log"
CustomLog "logs/joanaweb.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/lifestylepro"
ServerName lifestylepro
ServerAlias lifestylepro
<Directory "C:/wamp/www/lifestylepro">
AllowOverride All
Require local
</Directory>
ErrorLog "logs/lifestylepro.log"
CustomLog "logs/lifestylepro.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/xxxxxTranslations"
ServerName xxxxxTranslations
ServerAlias www.xxxxxTranslations
<Directory "C:/wamp/www/xxxxxTranslations">
AllowOverride All
Require local
</Directory>
ErrorLog "logs/xxxxxTranslations.log"
CustomLog "logs/xxxxxTranslations.log" common
</VirtualHost>
现在有 HOSTS 文件。这需要包括两个 IPC4 的 IP 地址,即 127.0.0.1 以及 IPV6 的 IP 地址,即 ::1
因此,将您的 HOSTS 文件更改为此,删除不必要的重复并添加 IPV6 引用:-
127.0.0.1 localhost
127.0.0.1 wordpress
127.0.0.1 joanaweb
127.0.0.1 lifestylepro
127.0.0.1 xxxxxTranslations
::1 localhost
::1 wordpress
::1 joanaweb
::1 lifestylepro
::1 xxxxxTranslations
现在要确保将它们加载到 dnscache 中,使用“以管理员身份运行”选项启动命令窗口并运行这 2 个命令。
或者,只需重新启动,以使这些成为最新的。
net stop dnscache
net start dnscache
现在重新启动 Apache,以便获取这些更改,然后尝试使用您的虚拟主机。
【讨论】:
您好,感谢您的建议。我试过了,但不幸的是它没有用。然后我将httpd.conf
行 24
中定义,因此对 APACHE2.4.9
的测试也无关但你最清楚!
感谢您的解释,我实际上并不知道最好的:/ 但那篇文章是我发现的唯一一篇提到与我正在努力解决的问题相同的问题......幸运的是,直到现在我不需要访问 localhost,但我仍然希望找到它的问题。
好的,所以,如果你安装了 WAMPServer,一切都安装在 \wamp
文件夹内。 WAMPServer 主页的位置(您所称的 localhost)在 \wamp\www
中,基本上是一个名为 \wamp\www\index.php
的文件除非您损坏了此文件夹或删除了原始内容您还添加了HOSTS
文件的新 joanweb?以上是关于在 WAMP 上安装虚拟主机后无法访问默认 localhost的主要内容,如果未能解决你的问题,请参考以下文章
更改root密码后无法访问wamp phpmyadmin..? [关闭]