Solve Nginx 13: Permission denied while connecting to upstream error

created at 08-16-2021 views: 423

problem

When doing Nginx load, we often encounter this situation:

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

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 127.0.0.1:5601, and remote access is also normal, even if Nginx does forwarding, it will not work.

Reason

It is because of the limitations of SeLinux.

solution

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:

SELINUX=disabled

just restart the machine.

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