从同一本地网络上的计算机访问虚拟主机 [英] Accessing virtual host from computer on same local network

查看:23
本文介绍了从同一本地网络上的计算机访问虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行设置,以便我可以从计算机 B 访问计算机 A 中虚拟主机上的网站.A 和 B 都在同一个网络上.我在 Win 7 上使用 xampp.

I am trying to make a setup so that I can access my website on a virtual host in computer A from computer B. Both A and B are on the same network. I am using xampp on Win 7.

所以问题是计算机 A(服务器)在 httpd-vhosts.conf 文件中有如下虚拟主机配置.

So here is as the problem goes computer A(server) has a virtual host configuration as follows in the httpd-vhosts.conf file.

NameVirtualHost project:81

<VirtualHost project:81>

    DocumentRoot "D:/work/website"
    ServerName project:81
    <Directory "D:/work/website">
    Options Indexes FollowSymLinks Includes ExecCGI    
    AllowOverride All
    Order Allow,Deny
    Allow from all
    </Directory>
</VirtualHost>

(使用81端口作为80端口有IIS运行,但是对这些东西不太了解)

(using port 81 as port 80 has IIS running, dont know much about these things however)

此配置在本地机器(服务器)上运行良好.即浏览器地址栏中的 project:81 会按原样打开网站.

this configuration works fine on the local machine(server). i.e project:81 in the address bar of the browser opens up the website as it should.

现在在计算机 B(客户端)上,我更改了 hosts 文件以包含服务器的 IP 以及虚拟主机的名称,例如:-

Now on computer B(client) I changed the hosts file to contain the IP of the server along with the name of the virtual host like:-

192.168.1.7 项目

192.168.1.7 project

现在,当我在客户端浏览器上输入 project:81 时 .. 它会将我带到服务器,但不会将我带到虚拟主机目录,而是将其带到默认目录 .. 即在我的情况下是

now when I enter project:81 on the client browser .. it takes me to the server but its not taking me to the virtual host directory, instead it takes to the default directory .. i.e in my case is

C:xampphtdocs

C:xampphtdocs

现在我卡住了,无法让客户端指向当前目的地.因此,任何人都可以建议我在这里做错了什么或我需要做的其他事情才能从客户端计算机访问正确的虚拟主机站点.

Now I am stuck and unable to make the client to point to the current destination. So can anybody suggest what I am doing wrong here or something else I need to do in order to have access to the correct virtual host site from the client machine.

提前感谢您的帮助

推荐答案

好吧,所以 Seto El Kahfi 对我的老问题的回答让我在 Apache 的网站上做更多的研究和阅读.

Ok So Seto El Kahfi's reply to my very old question led me to do some more research and reading on Apache's website.

所以我得到的是,我的 NameVirtualHost 指令不正确.所以代替这个,

So what I got is this, my NameVirtualHost directive was improper. So Instead of this,

NameVirtualHost project:81

<VirtualHost project:81>

    DocumentRoot "D:/work/website"
    ServerName project:81
    <Directory "D:/work/website">
    Options Indexes FollowSymLinks Includes ExecCGI    
    AllowOverride All
    Order Allow,Deny
    Allow from all
    </Directory>
</VirtualHost>

我要做的就是这个.

NameVirtualHost *:81

<VirtualHost *:81>

    DocumentRoot "D:/work/website"
    ServerName project
    <Directory "D:/work/website">
    Options Indexes FollowSymLinks Includes ExecCGI    
    AllowOverride All
    Order Allow,Deny
    Allow from all
    </Directory>
</VirtualHost>

注意 ' * ' ,我也可以在那里使用 IP 地址.(在这种情况下,我的服务器(机器 A)本地 IP)都可以工作.现在我所要做的就是在客户端机器上输入project:81",我就得到了我的眼睛希望看到的东西.. :)

Notice the ' * ' , I could have used an IP Address there too.(In this case my server's(machine A) local IP) both work. Now all I had to do is enter "project:81" on the client machine, and I get what my eyes wished to see.. :)

我从中得到的东西很少.

1)如何使用NameVirtualHost(或者它的目的基本上是什么.).在这里阅读更多http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost这个也不错 http://www.thegeekstuff.com/2011/07/apache-虚拟主机/

Few things I got from this.

1) How to use NameVirtualHost(or what it's purpose basically is.). Read More here http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost This one is also good http://www.thegeekstuff.com/2011/07/apache-virtual-host/

2)您可以通过命令行使用它:

2)You can use this via command line:

httpd -D DUMP_VHOSTS

了解您的虚拟主机是如何设置的(如果您的设置有问题,还会给您一些关于优先级的警告)

to know how your virtual hosts are setup(will also give you some warnings regarding precedence if something's wrong with your setup)

3) 别人帮助你的姿态让你帮助自己.. :) 所以继续帮助和摇摆.

3)Other's gesture to help you makes you help yourself.. :) So keeping helping and rocking.

这篇关于从同一本地网络上的计算机访问虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆