Reputation: 1864
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
Check SELinux Status: Verify that SELinux is enabled and enforcing on your system:
sestatus
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
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
Load the SELinux Policy: Load the generated policy module into SELinux:
sudo semodule -i nginx_connect.pp
Check SELinux Status: Verify that the new policy has been loaded successfully:
sudo semodule -l | grep nginx_connect
Restart NGINX: After adjusting SELinux policies, restart NGINX to apply the changes:
sudo systemctl restart nginx
This works for me
Upvotes: 1
Views: 407