How To Install HAProxy on AlmaLinux 8

Install HAProxy on AlmaLinux 8

In this tutorial, we will show you how to install HAProxy on AlmaLinux 8. For those of you who didn’t know, HAProxy is one of the most popular open-source load balancing software, which also offers high availability and proxy functionality. It is particularly suited for very high-traffic websites and powers quite a number of the world’s most visited ones.

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 the step-by-step installation of the HAProxy high-performance TCP/HTTP load balancer on AlmaLinux 8. You can follow the same instructions for Rocky Linux.


  • A server running one of the following operating systems: AlmaLinux 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Network Details.

Below is our network server. There are 2 web servers running with Apache2 and listening on port 80 and one HAProxy server:

Web Server Details:
  Server 1:
  Server 2:
HAProxy Server: 
  HAProxy:     haproxy     

Install HAProxy on AlmaLinux 8

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo dnf update
sudo dnf install epel-release

Step 2. Installing HAProxy on AlmaLinux 8.

HAProxy is available in the default  AlmaLinux 8 repositories. Now run the following command below to install it:

sudo dnf install haproxy

After the HAProxy is installed, now start the HAProxy service and enable it to start at system reboot:

sudo systemctl start haproxy
sudo systemctl enable haproxy

Step 3. Configure HAProxy.

HAProxy has a default path for the configuration file at /etc/haproxy/haproxy.cfg .Now modify two sections frontend and backend. In the Frontend section, you will need to define HAProxy IP its port, stats URI and backend name. In the Backend section, you will need to define the load balance algorithm, backend server’s name, IPs, and port:

nano /etc/haproxy/haproxy.cfg

Modify the following lines:

frontend http_balancer
    option http-server-close
    option forwardfor
    stats uri /haproxy?stats

default_backend     Apache_webservers

backend apache_webservers
    mode        http
    balance     roundrobin
    option httpchk HEAD / HTTP/1.1\r\nHost:\ localhost    
    server  apache1  check
    server  apache2  check

Save and close also edit /etc/rsyslog.conf file:

nano /etc/rsyslog.conf

Uncomment the following lines:

input(type="imudp" port="514")

Save and close the file. After that create haproxy.conf file for rsyslog with the following command:

nano /etc/rsyslog.d/haproxy.conf

Add the following lines:

local2.=info     /var/log/haproxy-access.log
local2.notice    /var/log/haproxy-info.log

Then, start the rsyslog service and enable it to start at system reboot:

sudo systemctl start rsyslog
sudo systemctl enable rsyslog

Once you have configured HAProxy, its time to restart the service:

sudo systemctl restart haproxy

Step 4. Configure Firewall.

We will add the HAProxy to the AlmaLinux 8 firewall and update the rules with the following commands:

sudo firewall-cmd --add-port=8088/tcp --permanent
sudo firewall-cmd --reload

Step 5. Configure Backend Servers.

Now we install the Apache server on both backend servers:

sudo apt install httpd

Once the Apache server has been installed, start the Apache service and enable it to start at system reboot:

sudo systemctl start httpd
sudo systemctl enable httpd

Then, modify the default index.html file on both backend servers:

nano /usr/share/httpd/noindex/index.html

Remove all lines and add the following line:

Welcome Apache Web Server 1

On the second backend, edit the index.html file with the following command below:

nano /usr/share/httpd/noindex/index.html

Remove all lines and add the following line:

Welcome Apache Web Server 2

Finally, HAProxy is configured to forward all incoming requests to the backend servers based on the load-balancing algorithm. Now, it’s time to check whether HAProxy is working properly or not. Open your web browser and type the HAProxy IP in the URL You should see your first Apache Web Server 1, and Next, refresh the same page again, you should see your Apache Web Server 2.

Congratulations! You have successfully installed HAProxy. Thanks for using this tutorial for installing the HAProxy high-performance TCP/HTTP load balancer on your AlmaLinux 8 system. For additional help or useful information, we recommend you check the official HAProxy website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button