I'm trying to set up my project into virtual machine so I can work with it from my host machine. I've set up port forwarding in vagrantfile and when I run 'vagrant up' everything is ok and there is no errors. But when I try to access to my app in VM from host machine, I can't.
My vagrant file is realy simple:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise32"
config.vm.network :forwarded_port, host: 4567, guest: 8001
config.vm.synced_folder "data", "/home/vagrant/projects/myapp/"
end
On start I get this:
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 8001 => 4567 (adapter 1)
default: 22 => 2222 (adapter 1)
Looks like there is everything OK, but when I try to access to 127.0.0.1:4567 from my host (and I run my app in guest machine on 127.0.0.1:8001), I get ERR_EMPTY_RESPONSE
err_code in browser.
What I'm doing wrong?
Best Answer
First of all, I'm sorry if it's not the case, i don't have reputation for comments.
Maybe your service is listening on 127.0.0.1 when it should be listening on 0.0.0.0. You can check it running this command on the guest:
netstat -lnptu | grep ':8001'
At the fourth column you should get 0.0.0.0:8001. If it's not the case, look for the binding option on the service you are running.
PS: If it's a Sinatra Server (what I'm guessing by the host port number) take a look at the :bind topic on this page.