You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS系统中Node.js无法连接8080端口的排查求助

Node.js Web服务器在Oracle Linux 8.7上无法通过8080端口访问的排查建议

我在Oracle Linux 8.7上用Node.js搭建了Web服务器,但外部无法通过8080端口访问,22端口可正常tcping通。

Node.js服务器代码

const http = require('http');
const hostname = '0.0.0.0';
const port = '8080';

httpd = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('Hello World!');
});

httpd.listen(port, hostname, function(){
    console.log('Server Start');
});

tcping测试结果

C:\Users\user>tcping -p 22 <centOS IP>
Probing <centOS IP>:22/tcp - Port is open - time=14.019ms
Probing <centOS IP>:22/tcp - Port is open - time=13.159ms
Probing <centOS IP>:22/tcp - Port is open - time=8.601ms
Probing <centOS IP>:22/tcp - Port is open - time=9.896ms

C:\Users\user>tcping -p 8080 <centOS IP>
Probing <centOS IP>:8080/tcp - No response - time=2010.980ms
Probing <centOS IP>:8080/tcp - No response - time=2008.277ms
Probing <centOS IP>:8080/tcp - No response - time=2008.509ms
Probing <centOS IP>:8080/tcp - No response - time=2000.949ms

已完成的检查

  • 确认8080端口处于监听状态(netstat输出显示0.0.0.0:8080处于LISTEN状态)
  • 已关闭系统层面防火墙:firewalld处于masked/inactive状态,iptables服务未安装,nftables处于inactive状态

相关命令输出

[opc@instance-20220607-1056 webTest]$ netstat -tnlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:9003          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
.
.

[opc@instance-20220607-1056 webTest]$ sudo service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.

[opc@instance-20220607-1056 webTest]$ sudo systemctl status nftables
nftables.service - Netfilter Tables
Loaded: loaded (/usr/lib/systemd/system/nftables.service; disabled; vendor p>
Active: inactive (dead)
Docs: man:nft(8)
lines 1-4/4 (END)

[opc@instance-20220607-1056 webTest]$ sudo systemctl status firewalld
firewalld.service
Loaded: masked (Reason: Unit firewalld.service is masked.)
Active: inactive (dead)

Jan 05 17:49:52 instance-20220607-1056 systemd[1]: Starting firewalld - dynamic firewall daemon...
Jan 05 17:49:54 instance-20220607-1056 systemd[1]: Started firewalld - dynamic firewall daemon.
Jan 05 17:49:54 instance-20220607-1056 firewalld[1480]: WARNING: AllowZoneDrifting is enabled. This is consi>
Jan 05 20:38:06 instance-20220607-1056 systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jan 05 20:38:10 instance-20220607-1056 systemd[1]: firewalld.service: Succeeded.
Jan 05 20:38:10 instance-20220607-1056 systemd[1]: Stopped firewalld - dynamic firewall daemon.

[opc@instance-20220607-1056 webTest]$ sudo lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: OracleServer
Description:    Oracle Linux Server release 8.7
Release:        8.7
Codename:       n/a

还需要检查的内容

  • 本地验证服务可用性:在服务器上执行curl http://localhost:8080或telnet localhost 8080,确认服务本身是否能正常响应。如果本地也无法访问,需检查Node进程是否正常运行,或代码是否存在问题(比如httpd未声明为局部变量,建议添加let/const避免全局变量异常)。
  • 云服务器安全组规则:如果是云服务商提供的服务器(如Oracle Cloud),需确认安全组是否允许外部IP访问8080端口的TCP流量。云安全组独立于系统防火墙,即使系统防火墙关闭,安全组拦截也会导致无法访问。
  • SELinux状态检查:Oracle Linux默认启用SELinux,执行sestatus查看状态,若为Enforcing模式,可能阻止Node.js绑定端口或对外提供服务。可临时执行sudo setenforce 0关闭SELinux测试,若能正常访问,再配置SELinux规则允许Node.js的网络权限。
  • 端口监听进程验证:执行sudo netstat -tnlp | grep 8080获取监听端口的PID,再用ps -p <PID>确认该进程是否为Node.js。若不是,说明端口被其他程序占用,需更换端口或停止占用进程。
  • 网络路由与NAT设置:确认服务器是否拥有正确的公网IP,若通过NAT网关访问公网,需检查网关是否配置了8080端口的转发规则。
  • Node.js服务日志排查:用ps aux | grep node确认Node进程是否存在,若进程异常退出,检查启动命令是否有错误,或使用守护进程(如pm2)时是否配置正确。

内容的提问来源于stack exchange,提问作者Jinhee Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 22:35:37