Httpd/ apache2 issue "failed to make connection to backend" on CentOS

Ever came across this issue of "503 Service Unavailable" when you trying to setup a ProxyPass to your local (127.0.0.1) with Apache2/httpd?

Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Well now there's a really quick fix for it. Just check your error_log of httpd or apache2:

# for httpd
sudo tail /var/log/httpd/error_log

# for apache2
sudo tail /var/log/apache2/error_log

If you see something like this:

[Wed Dec 18 14:45:21.586920 2019] [proxy:error] [pid 15448] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:27447 (127.0.0.1) failed
[Wed Dec 18 14:45:21.586969 2019] [proxy_http:error] [pid 15448] [client 94.102.49.104:45290] AH01114: HTTP: failed to make connection to backend: 127.0.0.1
[Wed Dec 18 14:49:28.842439 2019] [proxy:error] [pid 15450] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:27447 (127.0.0.1) failed
[Wed Dec 18 14:49:28.842492 2019] [proxy_http:error] [pid 15450] [client 162.158.219.94:65190] AH01114: HTTP: failed to make connection to backend: 127.0.0.1

Then you came to the right place! Just run this command:

sudo /usr/sbin/setsebool -P httpd_can_network_connect 1

then restart httpd/ apache2 and you're good to go!


In case you get the warning:

setsebool:  SELinux is disabled.

Then you have to enable SELinux first by opening the file /etc/selinux/config:

nano /etc/selinux/config

Change the SELINUX to enforcing then save it:

SELINUX=enforcing

Reboot your computer using sudo reboot. After that you can run the command again:

sudo /usr/sbin/setsebool -P httpd_can_network_connect 1

Ta-da! Now your httpd can establish a connection to your local application!