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

我在GCE上运行node.js上有一个简单的服务器,但是我无法从外部访问服务器。 由于没有太多的迹象,我不确定什么是错的。 这是我的代码:

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'); 

我可以ping通由GCE公开的外部IP,但我无法达到它。 有没有其他的设置,我需要这个工作? 还是代码不正确?

我从Hiren的评论中解决了这个问题。 为了进一步,我实际上做了他之前所说的,但是做的是标签。 如果你随机设置了一些东西,那么它就不能工作,因为它需要匹配一些其他的标签。 但是我只是为了testing而将其留空,并将其应用到所有实例,并工作。