2

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?

2
  • Does it work fine when you use vagrant ssh and then get site from local port 8001?
    – 3h4x
    Jul 27, 2014 at 13:00
  • Yes, from guest machine I can get my app page with curl. Jul 27, 2014 at 13:08

1 Answer 1

6

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.

2
  • I run my up on 0.0.0.0:8001 (it is django app, I used 8000 port, but looks like it is used by some other service) and now I can access it from host machine! Thanks!) Is this secure to run on 0.0.0.0 IP? Jul 27, 2014 at 15:13
  • Don't worry! It's safe. Binding on 0.0.0.0 it's just a way to tell your service to listen on every interface you have and 127.0.0.1 is just one of those interfaces. If you want to know more about that see this question. By the way, you're welcome! Nice to know you've solved your problem.
    – warantesbr
    Jul 27, 2014 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .