连接到在无业游民计算机上运行的Node JS服务器 [英] Connect to node js server running on vagrant machine

查看:43
本文介绍了连接到在无业游民计算机上运行的Node JS服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vagrant VM上运行了一个简单的node http server.我想用我的本地计算机上的浏览器来解决这个问题.

I have a simple node http server running on a vagrant VM. I would like to address to it with my browser on my local machine.

varhttp=require("http");

http.createServer(function(request,response){
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
}).listen(3000);

这是我的Vagrantfile:

This is my Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.box = "ubuntu/xenial64"
    config.vm.network "forwarded_port", guest: 80, host: 8080
    config.vm.provision "shell", path: "config.sh"
end

我不知道如何从浏览器中找到地址.

I can't figure out how to address it from my browser.

每当我在无业游民的VM中执行curl localhost:3000时,都会收到Hello world消息.

Whenever I do curl localhost:3000 in the vagrant VM, I get the Hello world message.

每次尝试打开localhost:8080时,都会从本地计算机上获得This site can’t be reached,如

From my local machine I get This site can’t be reached whenever I try to open localhost:8080, as suggested in Vagrant forwarding.

推荐答案

您的转发配置转发80,但是您的应用程序侦听3000.解决该问题,它应该可以工作.

Your forward config forwards 80, but your application listens on 3000. Fix that and it should work.

这篇关于连接到在无业游民计算机上运行的Node JS服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆