0

wamp 用のマルチ サイトを作成しました。これはサーバー pc で正常に動作していますが、ネットワークからこれらのサイトにアクセスする方法がわかりません。すべてのサイトのフォルダーを、「www」の前のフォルダーである wamp のルートに配置しました。

これは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 は、それぞれにセットアップした 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

クライアント PChttp://client1.mainは、最初のサイトへのアクセスとhttp://client2.main2 番目のサイトへのアクセスに使用します。

もちろん、WAMPServer を実行している PC からもサイトにアドレス指定する必要がありますhttp://client1.main。そして、WAMPServer PC の HOSTS ファイルをネットワーク上のものと同じになるように変更します。

于 2013-11-01T00:48:36.307 に答える