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.
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.
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.
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.
Click Firewall > Port forwarding. Click the menu icon (...) next to the appropriate port forwarding rule and select Delete.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With