2017-06-06 76 views
0

我试图逃离作为本地测试服务器,我很难从托管Windows机器连接到nodejs应用服务器,但我可以连接到nginx服务器就好了。无法连接到托管在流浪机上的节点js服务器

我的无业游民文件:

Vagrant.configure("2") do |config| 
    config.vm.define "web" do |web| 
    web.vm.box = "ubuntu/trusty64" 
    web.vm.network "private_network", ip: "55.55.55.55" 
    end 

    config.vm.define "app_0" do |app_0| 
    app_0.vm.box = "ubuntu/trusty64" 
    app_0.vm.network "private_network", ip: "55.55.55.1" 
    end 

    config.vm.define "db" do |db| 
    db.vm.box = "ubuntu/trusty64" 
    db.vm.network "private_network", ip: "55.55.55.56" 
    end 
end 

我的节点JS从app_0 index.js(的HelloWorld)在55.55.55.1:

// Load the http module to create an http server. 
var http = require('http'); 

// Configure our HTTP server to respond with Hello World to all requests. 
var server = http.createServer(function (request, response) { 
    response.writeHead(200, {"Content-Type": "text/plain"}); 
    response.end("Hello World\n"); 
}); 

// Listen on port 80, IP defaults to 127.0.0.1 
server.listen(80, '0.0.0.0', function() { 
    console.log('Listening to port: ' + 80); 
}); 

其上运行使用sudo节点index.js和可见本地在流浪机上,但我无法连接到它从主机55.55.55.1:80

请不要标记这个副本:Connect to node js server running on vagrant machine,因为它不使用端口转发。

回答

0

我看到两两件事:

  • 55.55.55.x不是私网IP(见https://en.wikipedia.org/wiki/Private_network),所以你可能会达到一个有效的IP,甚至设置你的主机文件时,你可能有冲突。

  • 不要在结束与.1使用的地址,它是默认网关/路由器 所以如何流浪汉将到达主机。

从专用网络范围内选择一个有效的IP,它会工作

Vagrant.configure("2") do |config| 
    config.vm.define "web" do |web| 
    web.vm.box = "ubuntu/trusty64" 
    web.vm.network "private_network", ip: "192.168.55.10" 
    end 

    config.vm.define "app_0" do |app_0| 
    app_0.vm.box = "ubuntu/trusty64" 
    app_0.vm.network "private_network", ip: "192.168.55.11" 
    end 

    config.vm.define "db" do |db| 
    db.vm.box = "ubuntu/trusty64" 
    db.vm.network "private_network", ip: "192.168.55.12" 
    end 
end 
+0

咦,有一件事我不明白的是,55.55.55.1后仍然笔者从断开没有工作我网络。我尝试了10.0.0.10并像魅力一样工作。谢谢! – legokangpalla

相关问题