In this tutorial we will show you how to install HAProxy on your Debian 9. For those of you who didn’t know, For those of you who didn’t know, HAProxy is a free HTTP/TCP high availability load balancer and proxy server. It spreads requests among multiple servers to mitigate issues resulting from single server failure. HA Proxy is used by a number of high-profile websites including GitHub, Bitbucket, Stack Overflow, Reddit, Tumblr, Twitter and Tuenti and is used in the OpsWorks product from Amazon Web Services.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation HAProxy on a Debian 9 (Stretch) server.
Install HAProxy on Debian 9 Stretch
Step 1. Before we install any software, it’s important to make sure your system is up to date by running these following apt-get commands in the terminal:
Step 2. Network Details.
Below is our network server. There are 3 web servers running with Apache2 and listening on port 80 and one HAProxy server:
Server1: web1.myvpsource.com 192.168.1.101
Server2: web2.myvpsource.com 192.168.1.102
Server3: web3.myvpsource.com 192.168.1.103
HAProxy: haproxy 192.168.1.18
Debian 9 already ships with HAProxy 1.7 (latest stable release at time of writing), and we can simply install it using apt-get:
After the installation you can double check the installed version number with the following:
We have to modify the configuraion file of haproxy i.e. /etc/haproxy/haproxy.cfg as per our requirement. (Change this configuration as your network requirements). For more configuration details check this url.
### nano /etc/haproxy/haproxy.cfg
# Default SSL material locations
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
Since you have done with all necessary configurations for proxy server, verify configuration file before restarting service using following command:
If above command return output as “configuration file is valid” then restart HAProxy service:
Open your favorite browser and access port 80 on ip 192.168.0.18 (as configured above) in web browser and hit refresh. You will see that HAProxy is sending requests to backend server one by one (as per round robin algorithm).
Congratulation’s! You have successfully installed HAProxy. Thanks for using this tutorial for installing the latest version of HAProxy on Debian 9 Stretch server. For additional help or useful information, we recommend you to check the official HAProxy web site.