nodejs服务器无法从外部访问

nodejs server can't access from outside

各种方法都试过了,还是不行。 在这方面需要一些帮助。

运行 在 CentOS 版本 6.10 上 使用 PM2 启用 nodejs 服务器。

server.js

const http = require('http');

const hostname = '0.0.0.0';
const port = 3001;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('This is the Admin Side!\n');
});

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`);
});

curl localhost:3001 is working.

启用防火墙

iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:3001 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:3001

端口似乎打开

netstat -tnl | grep 3001
tcp        0      0 0.0.0.0:3001                0.0.0.0:*                   LISTEN  

提供商默认不允许端口 3001