Nodejs App在0.0.0.0:80不公开

jos*_*son 1 vps amazon-ec2 amazon-web-services node.js

我正在使用运行ubuntu和nodejs的ec2服务器.我认为这会创建一个有效的服务器,如果我转到我的ec2网址,它会响应.

var http = require("http");
var port = 80; 
var serverUrl = "0.0.0.0";
console.log("Starting web server at " + serverUrl + ":" + port); http.createServer(      
function(req, res) {
  timestamp = new Date();
  console.log("Request for URL " + req.url + " received at " + timestamp);
  if (req.url === '/error') {
    console.log('Throwing an error');
    throw "Oops";
  }
  res.end("Hello World " + timestamp);
}).listen(port, serverUrl);
Run Code Online (Sandbox Code Playgroud)

我已经使用了nodejs并且特意表达了一段时间,但从未试图在vps上自己部署它,任何建议都表示赞赏.

Dan*_*iel 7

确保在EC2安全组上打开端口80.

通过使用curl机器的命令行测试它在端口80上的应答.

curl -v http://localhost/
Run Code Online (Sandbox Code Playgroud)

如果它通过本地卷曲回答,您可能只是遇到防火墙问题.