1

I have a little issue when I try to use nodejs as a web server on vagrant (on OS X).

My config file is linked below, I have only nodejs and mongodb installed. The box IP is 10.10.56.101 (I needed another ip than 192.168.56.101 to work at my school).

I try to reach the nodejs server with the little script linked below. The script only listen on port 51160 and answer OK.

First I didn't get any answers and after searching I found that I needed to do a port forwarding and with a iptable it worked (the command linked below, on port 51160 instead of 8000).

I reinstalled the vagrant machine with the same configuration and I wasn't able to get the machine to work anymore.

I can curl localhost:51160 from inside the vagrant machine but I can't get anything from outside the VM.

Files :

nobe4
  • 2,802
  • 3
  • 28
  • 54

1 Answers1

3

if you can curl localhost:51160 from inside the vagrant machine, that means node.js service is file.

I didn't see the Vagrantfile, please check you have below lines in Vagrantfile

config.vm.network "forwarded_port", guest: 51160, host: 51160
config.vm.network :private_network, ip: "192.168.56.123"   # or other unused IP.

After updated, run vagrant provision, and try again to access by

curl http://192.168.56.123:51160 

from your own computer.

BMW
  • 42,880
  • 12
  • 99
  • 116
  • It works but initially I wanted to access the port 80. And when I set `guest: 51160, host: 80`. I get : `Failed to connect to 10.10.55.22 port 80: Connection refused` – nobe4 Dec 18 '14 at 08:40
  • 1. do you have web service running on your own computer? 2. set a fix private ip will be easier, which you needn't adjust IP address every time, when up the vagrant instance. – BMW Dec 18 '14 at 09:28
  • 1 : nop 2 : the guest private ip is fixed, I can have another fixed port than 80 but it was the one I wanted... – nobe4 Dec 18 '14 at 09:30
  • can you confirm by this command? run `telnet localhost 80` on your own computer, do you get connected or not? – BMW Dec 18 '14 at 09:36
  • `telnet: connect to address 127.0.0.1: Connection refused telnet: Unable to connect to remote host` – nobe4 Dec 18 '14 at 09:37
  • do you have local admin right? active port (<1024) for unix/linux server need root permission. – BMW Dec 18 '14 at 09:40
  • That is why I used the following method to get rid of launching node with sudo : https://gist.github.com/kentbrew/776580#file-node-on-ec2-port-80-txt-L39 – nobe4 Dec 18 '14 at 09:41
  • Try this solution http://stackoverflow.com/questions/27277003/how-to-configure-vagrant-to-work-with-node-js – user468891 Jun 06 '16 at 12:57