简体   繁体   English

从本地网络中的计算机远程访问安装在VM上的Apache服务器

[英]Access Apache server installed on a VM remotely from computer in local network

I would like to access Apache from a computer that is inside my network, the problem is Apache is running on a virtual machine: 我想从我网络中的计算机访问Apache,问题是Apache在虚拟机上运行:

DIAGRAM 框图

(  [A: VM Running Apache] -- [B: Actual machine]  ) ------ [C: Actual machine]

IP's: IP的:

A: 192.168.55.55
B: 192.168.1.25

I can access A from B just fine, but not from C. (I get a message that reads 'the connection to the server timed out' after a while). 我可以从B访问A很好,但不能从C访问。(我得到一条消息,写了一段时间后'与服务器的连接超时'。

B: NETWORK INFO B:网络信息

在此输入图像描述

PD: The reason Apache is inside a VM is because I'm using Vagrant, not sure that has something to do with anything but I thought I'd mention it anyways. PD:Apache在VM中的原因是因为我正在使用Vagrant,不确定是否与任何事情有关,但我认为无论如何我都会提到它。

If your Vagrant version is >= 1.5 and using a public url doesn't create concerns, the solution should be trivial: 如果您的Vagrant版本> = 1.5并且使用公共URL不会产生问题,那么解决方案应该是微不足道的:

vagrant share

More info here . 更多信息在这里

This is what I did to get this working on my home network. 这就是我在家庭网络上工作所做的。

On the machine actually running Vagrant, edit the Vagrantfile and port forward 8088 (or whatever port # you choose) from the Host ('Actual Machine' as you called it) to port 80 on the Guest ('VM Running Apache' as you called it). 在实际运行Vagrant的机器上,编辑Vagrant文​​件并将主机8088 (或您选择的任何端口#)转发到主机(您调用它的“实际机器”)到客户机上的端口80 ('VM Running Apache',如您所说它)。

Do a normal vagrant up and you should see the port forwarding happening on boot up. 做一个正常的流浪汉 ,你应该看到启动时发生端口转发。 I personally have approximately 8 virtual hosts running inside my Vagrant box each with their own host name. 我个人大约有8个虚拟主机在我的Vagrant盒子里运行,每个主机都有自己的主机名。 I edited my hosts file on the Host (machine 'B' above) in order to point these hostnames to the ip of the Vagrant box. 我在主机(上面的机器'B')上编辑了我的主机文件,以便将这些主机名指向Vagrant框的ip。 It works great and I can just put in something like mysite.dev in the address bar and that site pulls up on my local machine. 它工作得很好,我可以在地址栏中输入类似mysite.dev的东西,然后该站点在我的本地机器上运行。

Now to get this to work on another machine, within the same subnet as the Host machine, you will need to edit the hosts file on that second machine. 现在,要使其在与主机相同的子网内的另一台计算机上运行,​​您需要在该第二台计算机上编辑hosts文件。 Point the hostnames, my example was mysite.dev , to the actual ip address of the Host machine. 将主机名(我的示例是mysite.dev)指向主机的实际IP地址。 This will forward any instance of mysite.dev to the machine you have labeled as 'B' in your question. 这会将mysite.dev的任何实例转发到您在问题中标记为“B”的计算机。 The only problem is that this is just pointing to the standard port 80 like any normal webpage. 唯一的问题是,这只是像任何普通网页一样指向标准端口80 You want this traffic to actually get to machine 'A' in your question. 您希望此流量实际上可以在您的问题中找到机器'A'。 So instead of just putting mysite.dev into the address bar of the browser, put mysite.dev:8088 (or whatever port number you chose to forward to machine 'A' earlier). 因此,不要只将mysite.dev放入浏览器的地址栏,而是将mysite.dev:8088 (或者您选择转发的任何端口号转发到之前的机器'A')。

Now the traffic from 'C' will be sent to machine 'B' because the hosts file tells it to go there and the additional port you added to the address forces machine 'B' to forward that traffic to port 80 on machine 'A'. 现在来自'C'的流量将被发送到机器'B',因为hosts文件告诉它去那里,你添加到地址的附加端口强制机器'B'将该流量转发到机器'A'上的端口80 Machine 'A' receives the request and returns the data to machine 'B' which then forwards it back to machine 'C'. 机器'A'接收请求并将数据返回到机器'B',然后机器'B'将其转发回机器'C'。

The end result is machine 'C' seeing the page returned from machine 'A'. 最终结果是机器'C'看到从机器'A'返回的页面。

Hope that about sums it all up. 希望大家总结一下。

Good luck! 祝好运!

c0p c0p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM