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

SELinux启用系统中NGINX连接Node.js报Permission Denied错误的解决方法

解决SELinux环境下NGINX连接Node.js应用权限拒绝问题

Connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream

我在启用SELinux的系统上遇到NGINX尝试连接运行在3000端口的Node.js应用时出现“Permission denied”错误的问题,经过排查,通过调整SELinux策略解决了该问题,具体步骤如下:

  1. 检查SELinux状态:确认系统上SELinux已启用并处于强制模式,执行命令:
    sestatus

  2. 查看SELinux拒绝记录:检查SELinux审计日志中与NGINX尝试连接Node.js应用相关的拒绝记录,执行命令:
    sudo grep nginx /var/log/audit/audit.log | grep denied

  3. 生成SELinux策略:使用audit2allow工具根据审计日志中的拒绝记录生成SELinux策略,执行命令:
    sudo grep nginx /var/log/audit/audit.log | grep denied | audit2allow -M nginx_connect

  4. 加载SELinux策略:将生成的策略模块加载到SELinux中,执行命令:
    sudo semodule -i nginx_connect.pp

  5. 验证SELinux策略状态:确认新策略已成功加载,执行命令:
    sudo semodule -l | grep nginx_connect

  6. 重启NGINX:调整SELinux策略后,重启NGINX以应用更改,执行命令:
    sudo systemctl restart nginx

该方法对我有效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 11:03:32