HAProxy is a powerful open-source software that enables load balancing and proxy con­fig­ur­a­tion for TCP- and HTTP-based ap­plic­a­tions. It can be installed on Debian 12 in just a few steps and is often used in highly available systems to ef­fi­ciently dis­trib­ute requests, thus improving ap­plic­a­tion stability and per­form­ance.

What is HAProxy?

HAProxy (High Avail­ab­il­ity Proxy) is a high-per­form­ance and reliable load balancer and reverse proxy that’s used for dis­trib­ut­ing network and ap­plic­a­tion traffic. The ap­plic­a­tion supports both Layer 4 (Transport Layer, e.g., TCP) and Layer 7 (Ap­plic­a­tion Layer, e.g., HTTP) of the OSI model with regard to load balancing. Thanks to its low latency, high ef­fi­ciency and com­pre­hens­ive con­fig­ur­a­tion options, HAProxy is suitable for companies of all sizes.

Companies and de­velopers use HAProxy to balance the load across multiple backend servers, intercept server outages and improve overall ap­plic­a­tion per­form­ance. The software plays a central role in many web in­fra­struc­tures, es­pe­cially in highly available and scalable ap­plic­a­tions. Its main features include SSL/TLS ter­min­a­tion, backend server health checks, rate limiting and DDoS pro­tec­tion mech­an­isms.

Dedicated Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres

How to install HAProxy on Debian step by step

Step 1: Update the system

Before in­stalling HAProxy, you should update your Linux dis­tri­bu­tion. This ensures that all packages are up to date and that the in­stall­a­tion runs smoothly.

The following command updates the package lists and installs all available updates for Debian 12:

sudo apt update && sudo apt upgrade -y
bash

Step 2: Install HAProxy

Debian 12 includes HAProxy in its official package sources, so in­stall­a­tion is easy using the built-in package manager apt.

sudo apt install haproxy -y
bash

This command downloads and installs HAProxy with all required de­pend­en­cies.

Step 3: Check HAProxy version

After in­stall­a­tion, you should check whether HAProxy was installed suc­cess­fully. You can do this by re­triev­ing the installed version of HAProxy:

haproxy -v
bash

The output should look something like this:

Image: Screenshot of the current HAProxy version in the terminal
After you run the command, the currently installed version of HAProxy will be displayed in your terminal.

This ensures that HAProxy has been installed correctly.

Step 4: Enable HAProxy as a service

In order for HAProxy to start auto­mat­ic­ally at system startup and run per­man­ently, the service must be enabled and started.

sudo systemctl enable haproxy
sudo systemctl start haproxy
bash

Finally, to check whether the service is running suc­cess­fully, the following command can be used:

sudo systemctl status haproxy
bash

If HAProxy is running correctly, you should see an active (running) output that looks something like this:

Image: Screenshot of the current HAProxy status in the terminal
You can see in the terminal output that HAProxy is now working without problems from the status ‘active (running)’.

Step 5: Basic con­fig­ur­a­tion of HAProxy

The HAProxy con­fig­ur­a­tion file is located at /etc/haproxy/haproxy.cfg. Before making any changes, it’s advisable to create a backup copy that you can fall back on in case of errors:

sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
bash

Now you can edit the file with an editor of your choice (such as Vim or nano):

sudo nano /etc/haproxy/haproxy.cfg
bash

A simple HAProxy con­fig­ur­a­tion could look like this:

global
	log /dev/log local0
	log /dev/log local1 notice
	chroot /var/lib/haproxy
	stats socket /run/haproxy/admin.sock mode 660 level admin
	stats timeout 30s
	user haproxy
	group haproxy
	daemon
defaults
	log global
	option httplog
	option dontlognull
	timeout connect 5000ms
	timeout client 50000ms
	timeout server 50000ms
frontend http_front
	bind *:80
	default_backend web_servers
backend web_servers
	balance roundrobin
	server server1 192.168.1.10:80 check
	server server2 192.168.1.11:80 check
txt

This con­fig­ur­a­tion dis­trib­utes HTTP requests across two web servers in a round-robin fashion. It’s divided into several sections. First, there’s the global section, which defines basic settings for HAProxy. For example, this section specifies the user account under which HAProxy runs, the number of con­cur­rent con­nec­tions allowed and where logs are stored. A chroot directory can also be defined to run HAProxy in a re­stric­ted en­vir­on­ment and thus increase security.

Following the global settings is the defaults section, where default values for all sub­sequent con­fig­ur­a­tions are defined. For example, this section specifies that HAProxy operates in HTTP mode and HTTP logging is enabled. Various timeouts are also defined.

The other sections of the con­fig­ur­a­tion file, such as frontend and backend, control the actual data traffic. The frontend section specifies which ports HAProxy accepts requests on and how they are forwarded. The backend section then defines the servers to which the traffic is forwarded. Load balancing al­gorithms can be used here.

After editing, you need to save the file and restart HAProxy:

sudo systemctl restart haproxy
bash

The in­stall­a­tion of HAProxy on Debian 12 is now complete. The con­fig­ur­a­tion can be adjusted at any time by changing the con­fig­ur­a­tion file.

GPU Servers
Power redefined with RTX PRO 6000 GPUs on dedicated hardware
  • New high-per­form­ance NVIDIA RTX PRO 6000 Blackwell GPUs available
  • Un­par­al­lel per­form­ance for complex AI and data tasks
  • Hosted in secure and reliable data centres
  • Flexible pricing based on your usage
Go to Main Menu