Saneesh
Saneesh

Reputation: 1864

Resolving "Permission Denied" Error for NGINX Connecting to Node.js Application on SELinux-Enabled System:

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

I encountered a "Permission denied" error when NGINX tried to connect to my Node.js application running on port 3000 on an SELinux-enabled system. After some troubleshooting, I managed to resolve the issue by adjusting SELinux policies. Here's how I did it

  1. Check SELinux Status: Verify that SELinux is enabled and enforcing on your system:

    sestatus

  2. Review SELinux Denials: Check the SELinux audit logs for any denials related to NGINX attempting to connect to the Node.js application:

    sudo grep nginx /var/log/audit/audit.log | grep denied

  3. Generate SELinux Policies: Use the audit2allow tool to generate SELinux policies based on the denials found in the audit logs:

    sudo grep nginx /var/log/audit/audit.log | grep denied | audit2allow -M nginx_connect

  4. Load the SELinux Policy: Load the generated policy module into SELinux:

    sudo semodule -i nginx_connect.pp

  5. Check SELinux Status: Verify that the new policy has been loaded successfully:

    sudo semodule -l | grep nginx_connect

  6. Restart NGINX: After adjusting SELinux policies, restart NGINX to apply the changes:

    sudo systemctl restart nginx

This works for me

Upvotes: 1

Views: 407

Answers (0)

Related Questions