Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant's port forwarding not working [closed]

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.

like image 913
Hank Gay Avatar asked May 12 '11 20:05

Hank Gay


People also ask

Why is my port not open after forwarding?

You will want to double-check the IP address and the port number of the server. Check if you can access that server in the local network. If you are unable to access the server in your local network, please check the settings of your server. Step 2: Check the port forwarding settings in the router.

What port does vagrant use?

It is common when running multiple Vagrant machines to unknowingly create forwarded port definitions that collide with each other (two separate Vagrant projects forwarded to port 8080, for example). Vagrant includes built-in mechanism to detect this and correct it, automatically.

How do I change my vagrant port?

Open VirtualBox and select the running VM, then hit Settings->Network->Port Forwarding and add the new rule to, for example, forward 127.0. 0.1:2223 to 10.0.

How do I stop port forwarding?

Click Firewall > Port forwarding. Click the menu icon (...) next to the appropriate port forwarding rule and select Delete.


1 Answers

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.

like image 136
Mitchell Avatar answered Oct 12 '22 10:10

Mitchell