Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
779 views
in Technique[技术] by (71.8m points)

windows - Access virtual host from another machine over LAN

  • I am using Windows 7 with Wamp 2.2 server.
  • I have setup 2 virtual hosts: www.project1.com and www.project2.com.
  • I have modified the "hosts", the httpd.conf, and the httpd-vhosts.conf files, to the changes I mentioned below.

Using my browser, when I type www.project1.com or www.project2.com, I successfully get my web pages opened on the laptop that has the server installed on.

Changes in the "hosts file": I've appended the followings to the end of the file:-

127.0.0.1       localhost
127.0.0.1       www.project2.com
127.0.0.1       www.project1.com

Changes in the httpd.conf file:-

Include conf/extra/httpd-vhosts.conf

Changes in httpd-vhosts file:-

NameVirtualHost *:80

<Directory "D:/websites/">
    AllowOverride All
    Order Deny,Allow
    Allow from all
    </Directory>
<VirtualHost 127.0.0.1>
    DocumentRoot "D:/websites/wamp/www/"
    ServerName localhost
</VirtualHost>


<VirtualHost 127.0.0.1>
    DocumentRoot "D:/websites/project1/"
    ServerName www.project1.com
</VirtualHost>


<VirtualHost 127.0.0.1>
    DocumentRoot "D:/websites/project2/"
    ServerName www.project2.com
</VirtualHost>


Now; since I can open these web pages from a browser in PC_1 (the one with the server), how can I access these web pages from a browser in PC_2? (I mean any PC connected to PC_1 via LAN.) See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In addition to danp's answer, you can access the virtual host without having to change the client machine's etc/hosts file by assigning a port to the virtual host. This is ideal if you want to access the server with a mobile or tablet device:

  1. Edit server's httpd.conf file at:

    wampinapacheapache2.2.xconfhttpd.conf
    

    Search for "Listen" (around line 61). You should see the following that allows for Apache to listen for port 80:

    Listen 0.0.0.0:80
    Listen [::0]:80
    

    Add the following lines to add listening for port 81 (or any port):

    Listen 0.0.0.0:81
    Listen [::0]:81
    
  2. Edit the httpd-vhosts.conf file at:

    wampinapacheapache2.2.xconfextrahttpd-vhosts.conf
    

    Change your "Virtual Host" tag to port 81:

    <VirtualHost *:81>
        DocumentRoot "D:/websites/project1/"
        ServerName www.project1.com
    </VirtualHost>
    
  3. Restart Apache server.

  4. On the client machine/tablet/mobile, on the web browser, enter the server's IP address (192.168.0.10, or whatever IP) followed by the port number in the following format:

    http://192.168.0.10:81
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...