node.js - nodejs服务器无法从外部访问

标签 node.js server centos centos6

我一直在尝试各种方法,仍然无法使其工作。
在这方面需要一些帮助。

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

服务器.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

关于node.js - nodejs服务器无法从外部访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54929481/

相关文章:

javascript - 如何解析 Javascript 中的 Javascript 代码以获取不在当前范围内的变量名?

node.js - socket.io 重新连接后再创建一个连接

node.js - node-sass 在 Windows 上安装时抛出错误

windows - 我可以在同一台服务器上安装、删除和重新安装相同的 SSL 证书吗

linux - 在没有root权限的情况下更新ldconfig缓存

php - pear 安装后 Nginx 不运行 php 文件

node.js - Node js Express 安装错误 'EACCES'、 'no such file'

linux - 在本地主机中链接(LAMP)

centos - 如何使用同一个CentOS 构建不同版本的RPM?

ssh - ssh 协议(protocol)是否将远程名称发送到远程计算机?