docker, nginx, centos,

502 Bad Gateway, Nginx reverse proxy and Docker containers in CentOS 7

Jan 31, 2023 · 1 min read · Post a comment

Sometimes, setting up HTTP/HTTPS GCP Firewall rule and Nginx reverse proxy to point to the Docker container port mapped as could be not enough, even though running curl on the same machine works as intended. So, here’s the catch.


  • CentOS 7
  • Docker
  • Nginx


Apparently, the good old SELinux was enabled by default. How could have I missed that.

Step 1. Enable the SELinux’s httpd_can_network_connect flag.

setsebool -P httpd_can_network_connect on

Step 2. Verify.

getsebool -a | grep httpd_can_network_connect

That should have done it.

quick “dirty” fix

But, if you want a quick, dirty fix, disable SELinux completely even though I would not recommend it. Run:

setenforce 0

Also, there is another way to do so. Update the SELINUX value to disabled.

Step 1. Open /etc/selinux/config and update the following line:


Step 2. Save the file and reboot the instance.


If you have any other great solutions on this topic, or even issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.