I am running a docker swarm on "swarm.example.com". On the server, there's a container running that can be accessed on "swarm.example.com:3000".
On server "example.com" I'm running an nginx reverse proxy with following rules
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://swarm.example.com:3000;
}
}
When I try to access app.example.com im getting 502 Bad Gatway error. Am I missing something ?
All servers are running CentOS 7.6
Thanks!
Best Answer
Trying to access the backend via the reverse proxy results in a 502 Bad Gateway error:
This is most probably because selinux by default doesn't allow outgoing connections for webservers, because that's usually something they don't do.
You will find entries like this in /var/log/nginx/error.log:
Additionally, you will find entries like this in /var/log/audit/audit.log:
Run the following command to allow nginx to connect to other hosts:
(The parameter
-p
makes the setting persistent. Otherwise it would be reset after the next reboot.)And now the proxy works:
If you want to know more, there is a very detailed article about nginx and selinux on the nginx website.