HaProxy: Cannot Bind Socket

As a total noob in system administration, it took me a while to realize that my machine’s services might have been stopped/restarted after Digital Ocean reached out about performing an emergency droplet migration after detecting problems on the physical server where my load balancing droplet/VM was running.

This was confirmed by running the following command and noting that the last time HaProxy had been active was on Digital Ocean’s maintenance day. (Please note that I am running these commands on Ubuntu.)


systemctl status haproxy.service


With this newfound knowledge, I attempted to restart HaProxy as sudo but ran into an error. After checking the HaProxy log (located in /var/log/), I found the following error message.


"Jul 15 17:10:13 ab1 haproxy[32723]: [ALERT] 202/171013 (32723) : Starting []: cannot bind socket [000:000.000.000:80]:"


Something was already occupying/listening on port 80! After using the the netstat command and feeding its output to grep we identified the culprit…Apache! Of course…my droplet was restarted and the apache2 service is probably set to start on boot.

sudo netstat -ltnp | grep -i ":80"


Our site was up and running after stopping the Apache service and starting HaProxy.

sudo service apache2 stop
sudo service haproxy start


I was able to confirm the issue arises on booting by checking our boot log with the following command.


sudo journalctl -b


Jul 15 16:34:11 ab1 systemd[1]: Started The Apache HTTP Server.
Jul 15 16:34:11 ab1 haproxy[978]: [ALERT] 195/163411 (978) : Starting frontend http: cannot bind socket [000.000.000.000:80]
Jul 15 16:34:11 ab1 haproxy[978]: Proxy www-https started.
Jul 15 16:34:11 ab1 haproxy[978]: Proxy www-https started.
Jul 15 16:34:11 ab1 haproxy[978]: Proxy app-backend started.
Jul 15 16:34:11 ab1 haproxy[978]: Proxy app-backend started.
Jul 15 16:34:11 ab1 systemd[1]: haproxy.service: Main process exited, code=exited, status=1/FAILURE
Jul 15 16:34:11 ab1 systemd[1]: haproxy.service: Failed with result 'exit-code'.
Jul 15 16:34:11 ab1 systemd[1]: Failed to start HAProxy Load Balancer.


Now if we want to prevent this from happening in the future, we have to set which services we want to auto start on boot which will be the topic of an upcoming post.


Hasta la vista baby!

Leave a Reply

Your email address will not be published.