Vagrant host-only IP connection not working in Chrome

875 views
Skip to first unread message

Josh Berlin

unread,
Jul 16, 2013, 1:49:16 PM7/16/13
to vagra...@googlegroups.com

I'm running this on OSX, and trying to connect to the host-only IP in the Vagrant file through Chrome.

In my Vagrant file i have this line:   config.vm.network :hostonly, "33.33.33.33"

I am trying to run an nginx server on the VM, and see the server on Chrome by going to http://33.33.33.33

My nginx configuration looks like this:

server {

       location / {

               proxy_pass http://127.0.0.1:2222;

       }

}

I am running a web server using gunicorn using this command: gunicorn app:app -b localhost:8000

When I navigate to the host-only IP, I get a connection failed error in chrome. If i change the gunicorn command to gunicorn app:app -b localhost:2222, it works. Why does port 8000 show a connection error?

From nginx logs:

2013/07/16 16:52:39 [error] 1748#0: *14 connect() failed (111: Connection refused) while connecting to upstream, client: 33.33.33.1, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:2222/favicon.ico", host: "33.33.33.33"

Thanks!

Rob Bast

unread,
Jul 17, 2013, 5:23:58 AM7/17/13
to vagra...@googlegroups.com
If you tell nginx to connect to port 2222, and then run your application on port 8000, there is a very likely chance that it will not be able to connect. This is called a pebkac error, and is generally very easy to solve.

Op dinsdag 16 juli 2013 19:49:16 UTC+2 schreef Josh Berlin het volgende:

Jesse Rhoads

unread,
Jul 17, 2013, 9:21:25 AM7/17/13
to vagra...@googlegroups.com
To be fair to Josh, this is probably a simple and common misunderstanding about how port forwarding works. 

Guest VM's have no knowledge of port forwarding from vagrant, their ports work on the ports you assign them in your guest OS applications.  So for example, If you have your unicorn on port 8000 on the guest VM with the IP 33.33.33.33 and you go to 33.33.33.33 port 8000 on the host machine or any of the guest machines on the same hostonly network, it will work as intended. 

You should only use port forwarding if you want the HOST machine to forward requests in, effectively making your host machine a bastion host of sorts. It lets people from OUTSIDE your host machine access your virtual machines, so it should generally be used with caution.

So, If you were running an nginx on the HOST machine, and you had a port forward on 2222 to 8000 on the Vagrant box, this nginx config would also work.


Best Regards,
-Jesse
Reply all
Reply to author
Forward
0 new messages