Vagrant's port forwarding not working

Hank Gay picture Hank Gay · May 12, 2011 · Viewed 96.4k times · Source

I'm running into a small problem at the end of the Getting Started guide for vagrant. I'm working on a CentOS basebox that has Apache2 running (provisioning via Puppet). I've set up port forwarding for web requests using the following line in Vagrantfile:

 config.vm.forward_port "web", 80, 4567

But when I make requests to that port, they fail. The error reported by Safari is 'Safari can’t open the page “http://localhost:4567/” because the server unexpectedly dropped the connection.'

I did a vagrant reload and saw "[default] -- web: 80 => 4567 (adapter 1)" in the scroll, so where should I begin to troubleshoot this? Thanks.

Answer

Mitchell picture Mitchell · May 14, 2011

I wanted to add an additional note that often this is caused by the server within the VM because it binds to 127.0.0.1, which is loopback. You'll want to make sure that the server is bound to 0.0.0.0 so that all interfaces can access it.

Some built-in app servers such as Django's development servers and some Ruby servers default to 127.0.0.1 by default so this is something to watch out for.

Other than that, what Steve said holds true: Make sure it works from within the VM and try some other simple servers to try and figure out if it is a configuration problem.