我一直在尝试各种方法,仍然无法使其工作。
在这方面需要一些帮助。
在 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/