HAProxy 503 / No servers found
I have been playing with haproxy lately, and I’m very impressed. I can see why it’s such a popular tool! I was able to configure load balancing for my app in 3 minutes flat.
The problem was, that the next day, my app was not available at the haproxy url, and nothing had changed in the configuration.
When running curl on the haproxy machine, I would get this error:
curl http://localhost
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>
I started to play around with my haproxy config, but nothing seemed to help. Finally, I started thinking about what could possibly have changed, and the answer was firewall, and selinux.
It turned out that selinux was the culprit, as a simple sudo setenforce 0
solved the problem. For production, we can add a rule, like so: setsebool -P haproxy_connect_any
.
Of course, the firewall had to allow haproxy as well. I followed this guide to set it up, but it didn’t work. I ended up using: firewall-cmd --add-service=http ; firewall-cmd --reload