0

我为 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 上的主机文件更改为:

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

在客户端的浏览器上,这些 url 都显示了主 wampserver index.php,而不是其分配的文件夹/站点。

4

1 回答 1

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 应该能够使用您在每个 PC 上设置的 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

然后客户端 PChttp://client1.main用于到达第一个站点并http://client2.main到达第二个站点 .. 等等

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

于 2013-11-01T00:48:36.307 回答