访问数字海洋上的node app - 此站点无法访问

Access node app on digital ocean - This site can't be reached

我无法访问我的数字海洋节点 js 应用程序。我已经通过 SSH 登录,从 Git 克隆了我的 Node 应用程序,安装了 npm,并在 droplet 上成功启动了该应用程序,但我收到错误

This site can't be reached

Digital Ocean 文档说您只需转到 <your website's ip>:<port>:

即可访问面向公众的网站

我通过转到 67.205.185.63:9000/ 来完成此操作(如您所见,我的应用程序在端口 9000 上 运行):

root@nodejs-512mb-nyc1-01:~/demos# npm start

live-demos@1.0.0 start /root/demos

node app.js

Demos is listening on port 9000

我还应该如何访问我的节点应用程序?


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

var app = express();
var port = process.env.PORT || 9000;

...

app.listen(port, function () {
    console.log('Demos is listening on port ' + port);
});

一些 Digital Ocean droplet(主要是 one-click apps)安装了 ufw 防火墙,默认情况下除了 22、80 和 443 之外的所有端口都被阻止。

要检查 ufw 是否已安装以及端口是 blocked/open,请执行以下操作:

sudo ufw status

输出:

To                         Action      From
--                         ------      ----
22                         LIMIT       Anywhere                  
80                         ALLOW       Anywhere                  
443                        ALLOW       Anywhere                  
22 (v6)                    LIMIT       Anywhere (v6)             
80 (v6)                    ALLOW       Anywhere (v6)             
443 (v6)                   ALLOW       Anywhere (v6)

要允许端口 9000 上的流量,请执行以下操作:

sudo ufw allow 9000/tcp

通过编写以下命令添加9000端口

sudo ufw allow 9000