Centos 6.4 Nodejs 外部没有响应

Centos 6.4 Nodejs external not responding

我是 ssh 和 Centos 6.4 的新手,我想 运行 端口 80 上的 nodejs。但无法使其在外部工作。

当我键入 netstat -anp | grep 8080 时,我可以看到我的节点正在监听。

tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      7976/node

但它不会对外开放。

我尝试将设置添加到 iptables,结果还是一样。它不起作用。

[root@culturalinfluences ~]# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http /* node.js port */
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:webcache /* node.js port */

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

这是我的 nodejs

var port = 8080;
app.listen(port, "0.0.0.0" ,function() {
    console.log("Listening on " + port);
});

谢谢四位理解,因为我对 linux 及其 iptables 系统真的很陌生。我相信像我一样的人会搜索同样的问题,我希望他们能从这个问题中找到答案。

感谢您的帮助。

你有一个

REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

就在您允许的 "http" 端口之前,因此永远不会达到这些规则。而是将 REJECT all 规则移至列表底部。

此外,您可能希望在 iptables 命令行上使用 -n 以确保端口号正确,而不是 80 而不是 8080例如。