我正在为我的一项 NodeJS 实验测试驾驶 AWS Lightsail。在服务器上使用 SSH 安装 NodeJS 并运行一个演示程序(见下文)。我可以使用命令“curl localhost:3000”从 SSH 终端看到输出“Hello World”。但是当我从网络外部访问它时,使用我家用 PC 中的网络浏览器,使用公共 IP 地址和端口号 3000,它说“无法访问此站点”我已经转发了服务器上的端口 3000边。
有什么我想念的吗?
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');
