Question

I would like to access Apache from a computer that is inside my network, the problem is Apache is running on a virtual machine:

DIAGRAM

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

IP's:

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: NETWORK INFO

enter image description here

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.

Was it helpful?

Solution

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).

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. I edited my hosts file on the Host (machine 'B' above) in order to point these hostnames to the ip of the Vagrant box. 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.

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. Point the hostnames, my example was mysite.dev, to the actual ip address of the Host machine. This will forward any instance of mysite.dev to the machine you have labeled as 'B' in your question. The only problem is that this is just pointing to the standard port 80 like any normal webpage. You want this traffic to actually get to machine 'A' in your question. 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).

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'. Machine 'A' receives the request and returns the data to machine 'B' which then forwards it back to machine 'C'.

The end result is machine 'C' seeing the page returned from machine 'A'.

Hope that about sums it all up.

Good luck!

c0p

OTHER TIPS

If your Vagrant version is >= 1.5 and using a public url doesn't create concerns, the solution should be trivial:

vagrant share

More info here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top