Solve Nginx 13: Permission denied while connecting to upstream error

created at 08-16-2021 views: 423


When doing Nginx load, we often encounter this situation:

2018/12/04 11:05:08 [crit] 2717#2717: *10 connect() to failed (13: Permission denied) while connecting to upstream, client:, server:, request: "GET / HTTP/1.1", upstream: "", host: ""

A 502 error is displayed when the client accesses, and the firewall and load balancing configuration are all normal. It is normal for this machine to access, and remote access is also normal, even if Nginx does forwarding, it will not work.


It is because of the limitations of SeLinux.


Turn off SeLinux

1. Temporary shutdown (no need to restart the machine):

setenforce 0 
  • setenforce 0: Set SELinux into permissive mode
  • setenforce 1: Set SELinux into enforcing mode (the default mode)

2. Modify the configuration file, need to restart the machine:

modify the /etc/selinux/config file, change SELINUX=enforcing to disabled:


just restart the machine.

created at:08-16-2021
edited at: 08-16-2021: