连接到在无业游民计算机上运行的Node JS服务器

Geo*_*ppa 0 virtualbox localhost portforwarding node.js vagrant

node http servervagrantVM 上运行很简单。我想用我本地计算机上的浏览器解决这个问题。

varhttp=require("http");

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

这是我的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
Run Code Online (Sandbox Code Playgroud)

我不知道如何从浏览器中解决它。

每当我curl localhost:3000在无所事事的VM中执行操作时,都会收到Hello world消息。

正如流浪转发中所建议的,This site can’t be reached每当我尝试打开时localhost:8080,我都会从我的本地机器上得到。

the*_*kim 5

config.vm.network "forwarded_port", guest: 3000, host: 8080