Vagrant, nodejs and iptable port forwarding

◇◆丶佛笑我妖孽 提交于 2021-01-28 11:19:35

问题


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 :

  • config.yaml : https://gist.github.com/nobe4/0bb16fdb23279d416656
  • server.js : https://gist.github.com/nobe4/639d63ef612f247d9309
  • iptable command : https://gist.github.com/kentbrew/776580#file-node-on-ec2-port-80-txt-L39

回答1:


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.



来源:https://stackoverflow.com/questions/27526391/vagrant-nodejs-and-iptable-port-forwarding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!