nodejs服务器无法从外部访问

问题描述 投票:0回答:1

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

在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正在运行。

启用防火墙

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  
node.js server centos centos6
1个回答
1
投票

提供程序默认情况下不允许端口3001

© www.soinside.com 2019 - 2024. All rights reserved.