What are the Symptoms?
This has bitten me badly twice now. I was deploying Centos 7.5 servers and trying to run HA Proxy on them through SystemD (I’m not sure if it is an issue otherwise).
Basically, no matter what port I use I get this message:
Starting frontend main: cannot bind socket [0.0.0.0:80]
Note that as I was too lazy to set up separate logging for the HAProxy config, I found this message in /var/log/messages with the other system messages.
Of course, seeing this your first thought is “he’s running another process on that port!”… but nope. Also, the permissions are set up properly, etc.
What is the Problem?
The problem here is actually SE Linux. I haven’t quite dug into why, but when running under SystemD, SELinux will deny access to all ports for HAProxy unless you go out of your way to allow it to access them.
How Do We Fix It?
The fix is very simple thankfully, just set this selinux boolean as a root/sudo user:
sudo setsebool -P haproxy_connect_any 1
…and voilà! if you restart your HAProxy it will connect fine. I spent a lot of time on this before I found a decent documentation and forum references in these places. I hope this helps you fix it faster! I also found a stack-overflow eventually… but the accepted/good answer is like 10 down so I missed it the first pile of times.