问题描述
最简单的服务器(与 '0.0.0.0' 相同的结果并删除此属性)
const http = require('http');
function handleRequest(a,b) {
console.log('!');
}
var server = http.createServer(handleRequest);
server.listen(4000,'0.0.0.0',function(){
console.log("Server is listening");
});
网络统计:
sudo netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 669/sshd: /usr/sbin
tcp 0 0 0.0.0.0:4000 0.0.0.0:* LISTEN 5631/node
tcp6 0 0 :::22 :::* LISTEN 669/sshd: /usr/sbin
访问 http://(server's IP):4000 的结果
无法访问此站点 (服务器的 IP)拒绝连接。
解决方法
好的,所以我不得不像这样在防火墙中打开端口:
firewall-cmd --zone=public --add-port=4000/tcp