Skip to content
MtrXTools

connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream

nginx is not allowed to connect to the backend

Seen in nginx error log on RHEL, CentOS, Rocky, Alma and Fedora (SELinux), or with Unix sockets

The operating system blocked nginx from opening the upstream connection, usually because of SELinux or socket file permissions.

Common causes

  • SELinux denies httpd (nginx) outbound network connections by default.
  • For a Unix socket, the nginx user cannot read or write the socket file.

How to fix it

  1. On SELinux systems, allow it: setsebool -P httpd_can_network_connect 1 (check denials with ausearch -m avc -ts recent).
  2. For PHP-FPM sockets, set listen.owner and listen.group in the pool config to the nginx user and restart PHP-FPM.
  3. Do not disable SELinux entirely to fix this.

Got a different message? Paste it into the error explainer.

Related errors

All 19 Web servers & certificates errors