繁体   English   中英

为什么我在CentOS中使用node.js无法连接8080端口?

[英]Why I can't connect port 8080 using node.js in CentOS?

我在 CentOS 8 中使用 node.js 创建了 web 服务器。但它不起作用。

这是我的 node.js web 服务器。

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');
});

我向 centos 发送了端口 22 和 8080 的 ping。我无法仅收到端口 8080 的响应。

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)(我关闭了firewalld,iptables ...)

<Linux>
[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

我还应该检查什么? 谢谢您的回答。

这个问题发生在 Oracle 云设置上,我参考下面的链接解决了这个问题。 关联

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM