【问题标题】:Linux Node JS listening on port 80 but not on other portsLinux Node JS 在端口 80 上侦听,但不在其他端口上
【发布时间】:2019-08-21 16:28:14
【问题描述】:

我是 linux 的入门级...

我让 node JS 监听 80 端口,一切正常。

但是当尝试不同的端口时它不起作用。

Firewalld is not enabled...

在浏览器中尝试时,我尝试使用 localhost:8080

有什么想法吗?

【问题讨论】:

    标签: node.js linux centos centos7


    【解决方案1】:

    如果防火墙已经运行则停止

     sudo systemctl stop firewalld
    

    检查iptable的状态

    如果尚未安装,则使用安装它

    yum install iptables-services
    
    sudo systemctl status iptables
    

    在启动时启用服务:

    systemctl enable iptables
    

    管理服务

    systemctl [stop|start|restart] iptables
    

    保存防火墙规则的方法如下:

    service iptables save
    

    使用此命令启动和启用防火墙

    sudo systemctl start firewalld
    sudo systemctl enable firewalld
    

    配置防火墙并添加要启用的IP和端口范围(可选)

    firewall-cmd --add-rich-rule='rule family="ipv4" source address="10.0.0.0/8" port port="11224-12224" protocol="tcp" accept'
    

    上面的命令获取 IP 和端口的范围。上面命令中需要替换IP和端口范围,一定要改x.x.x.x/n,这里n是端口数。

    【讨论】:

    • 感谢您的回答,但我的防火墙甚至无法正常工作。还有什么原因会导致这种情况?
    • 使用 80 端口时它可以工作...但没有任何东西,防火墙没有启用,还能是什么?
    • 对于防火墙,您必须定义 iptables。您是否尝试过使用此命令检查 iptable 状态 => sudo systemctl status iptables
    • 然后这个命令将启用防火墙 => sudo systemctl start firewalld sudo systemctl enable firewalld
    • 我收到“无法找到单元 iptables.service”。 ...可能是因为使用 CentOS 7?
    猜你喜欢
    • 2019-11-08
    • 2023-04-11
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2019-01-03
    • 1970-01-01
    相关资源
    最近更新 更多