Wamp在网络上运行良好但无法查看其他站点

时间:2013-10-28 11:11:53

标签: apache wamp

我为wamp创建了一个多站点,这在服务器PC上工作正常,但不确定如何从网络访问这些站点。我把所有的网站都放在了一起。文件夹位于wamp的根目录中,是' www'。

之前的文件夹

这里是apache conf的一部分

#virtual sites

NameVirtualHost *:80

<VirtualHost 127.0.0.1>
    ServerName localhost
    DocumentRoot "C:/wamp/www"
</VirtualHost> 

<VirtualHost 127.0.0.1>
    ServerName client1.localhost
    DocumentRoot "C:/wamp/client1"

    <Directory "C:/wamp/client1">
        allow from all
        order allow,deny    
        AllowOverride All
        Require all granted
    </Directory>

    DirectoryIndex index.html index.php
</VirtualHost>
<VirtualHost 127.0.0.1>
        ServerName client2.localhost
        DocumentRoot "C:/wamp/client2"

        <Directory "C:/wamp/client2">
            allow from all
            order allow,deny    
            AllowOverride All
            Require all granted
        </Directory>

        DirectoryIndex index.html index.php
    </VirtualHost>

这里是主持人条目

127.0.0.1       localhost
127.0.0.1   client1.localhost
127.0.0.1   client2.localhost
127.0.0.1   client3.localhost

这可以通过访问x.localhost(x =客户端文件夹)在服务器的PC浏览器中正常工作。我将客户端pc上的hosts文件更改为:

127.0.0.1       localhost
192.168.0.100   main
192.168.0.100   client1.main
192.168.0.100   client2.main
192.168.0.100   client3.main

在客户端浏览器上,这些网址都显示主要的wampserver index.php,而不是其指定的文件夹/网站。

1 个答案:

答案 0 :(得分:1)

假设您使用的是Apache 2.4.x,则更有可能发挥作用:

#virtual sites

#NameVirtualHost is no longer required in Apache 2.4.x so get rid of it.
#NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/wamp/www"
    # allow access from only this PC (security)
    Require local
</VirtualHost> 

<VirtualHost *:80>
    ServerName client1.main
    DocumentRoot "C:/wamp/client1"
    Options Indexes FollowSymLinks
    <Directory "C:/wamp/client1">
        AllowOverride All
        Require local
        # allow access from any ip in my subnet but not the internet
        Require ip 192.168.0
    </Directory>
    DirectoryIndex index.html index.php
</VirtualHost>

<VirtualHost *:80>
    ServerName client2.main
    DocumentRoot "C:/wamp/client2"
    Options Indexes FollowSymLinks
    <Directory "C:/wamp/client2">
        AllowOverride All
        Require local
        # allow access from any ip in my subnet but not the internet
        Require ip 192.168.0
    </Directory>
    DirectoryIndex index.html index.php
</VirtualHost>

现在您的联网PC应该能够使用您在每个站点上设置的HOSTS文件找到正确的站点。

我不知道hosts文件中的这行是什么,所以你可以删除它。

192.168.0.100   main

因此网络PC将其作为HOSTS文件

127.0.0.1       localhost
192.168.0.100   client1.main
192.168.0.100   client2.main
192.168.0.100   client3.main

客户端PC然后使用http://client1.main到达第一个网站,http://client2.main到达第二个网站等等

当然,您还必须将运行WAMPServer的PC上的站点作为http://client1.main来解决。并将WAMPServer PC上的HOSTS文件更改为与网络上的HOSTS文件相同。