繁体   English   中英

在WAMP上安装虚拟主机后无法访问默认本地主机

[英]Default localhost can't be accessed after installing virtual hosts on WAMP

我将非常感谢您为整天都在努力解决的问题提供的帮助...我使用WAMP在本地安装了WordPress,并且一切正常。 我在C:/ wamp / www内创建了一个名为wordpress的文件夹。 我只能通过在浏览器的URL上输入localhost来访问localhost,而当我决定安装另一个wordpress网站时,我却访问了键入localhost / wordpress / BUT的站点,但遇到了问题。 我在www内创建了第二个文件夹,命名为joanaweb,并按照本教程的步骤操作: http : //www.marolinedesign.com/tutorials/how-to-install-more-than-one-wordpress-site-on-your -local-wamp-server /加上我删除了httpd.conf上的conf 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>

我究竟做错了什么??

这也是我的主机文件中的所有代码(在注释之后):

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>

好吧,首先摆脱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中,请使用“以管理员身份运行”选项启动命令窗口,然后运行这两个命令。

或者,只需重新启动,以使这些成为最新。

net stop dnscache
net start dnscache

现在重新启动Apache,以便进行这些更改,并尝试使用您的虚拟主机。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM