简体   繁体   English

从Google Compute Engine外部访问Node.js服务器

[英]Reaching Node.js server externally from Google Compute Engine

I have a simple server on node.js running on GCE but I cannot reach the server externally. 我在GCE上运行的node.js上有一个简单的服务器,但是无法从外部访问该服务器。 I'm not sure what is wrong as there is not much indications. 我不确定什么地方出了问题,因为没有太多迹象表明。 Here is my code: 这是我的代码:

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var fs = require('fs');

app.use(function(req, res, next){
    console.log('Request Type:', req.method);
    console.log('Request query:', req.query);
    next();
});

app.use(bodyParser.urlencoded({     // to support URL-encoded bodies
  extended: true
}));

const PORT = 8080;

app.get("/getVideo", function (req, res){
  fs.readFile('./index.html', function (err, html){
     res.writeHead(200, {'Content-Type': 'text/html'});
     res.write(html);
     res.end();
   })
});


app.listen(PORT, '0.0.0.0');

I can ping the external ip exposed by GCE, but i just cannot reach it. 我可以ping通GCE公开的外部IP,但我无法达到它。 Is there any other setup i need this to work? 还有其他设置需要我使用吗? Or is the code incorrect? 还是代码不正确?

I solved it from Hiren's comment. 我从Hiren的评论中解决了。 To go further, I've actually did what he said before, but the thing that did it was the tags. 更进一步,我实际上做了他之前所说的,但是要做的是标签。 If you set something random, it would not work as it needs to match some other tags. 如果您将某些内容随机设置,则它将无法正常运行,因为它需要与其他一些标签匹配。 But I left it empty just to test, and it applied it to all instances, and worked. 但是我将其留空以进行测试,并将其应用于所有实例,并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM