How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Install and Set Up HAProxy on AlmaLinux, Rocky, or RHEL
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Server Management > How to Install and Set Up HAProxy on AlmaLinux, Rocky, or RHEL
Server Management

How to Install and Set Up HAProxy on AlmaLinux, Rocky, or RHEL

how7o
By how7o
Last updated: May 22, 2026
5 Min Read
Install HAProxy on AlmaLinux, Rocky Linux, or RHEL
SHARE

To install and set up HAProxy on AlmaLinux, Rocky Linux, or RHEL (the supported successors to CentOS), install the package with dnf, edit /etc/haproxy/haproxy.cfg to define a frontend and backend, open the firewall, and start the service. The instructions below also apply to CentOS 7 with yum in place of dnf, but CentOS 7 is end-of-life — prefer Alma/Rocky 9 for new installs.

Contents
  • Step 1 — install
  • Step 2 — minimal config
  • Step 3 — check config, then start
  • Step 4 — open the firewall
  • Step 5 — reload without dropping connections
  • Common configuration patterns
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on AlmaLinux 9 with HAProxy 2.4. Originally published 2023-10-04, rewritten and updated 2026-05-17.

Step 1 — install

# AlmaLinux / Rocky / RHEL 9
sudo dnf install haproxy -y

# CentOS 7 (legacy, EOL)
sudo yum install haproxy -y

# Confirm
haproxy -v
# HAProxy version 2.4.x ...

Step 2 — minimal config

Edit /etc/haproxy/haproxy.cfg. The default file is heavily commented; replace its frontend and backend blocks (or append) with a clear pair:

global
    log         127.0.0.1 local0
    daemon
    maxconn     4096

defaults
    log         global
    mode        http
    option      httplog
    option      dontlognull
    timeout connect 5s
    timeout client  30s
    timeout server  30s

frontend http_front
    bind *:80
    default_backend http_back

backend http_back
    balance     roundrobin
    server      web1 10.0.0.11:80 check
    server      web2 10.0.0.12:80 check

# Stats page — bind to localhost only in production
listen stats
    bind 127.0.0.1:8404
    stats enable
    stats uri /
    stats refresh 10s
    stats auth admin:CHANGE_ME
HAProxy on RHEL-family — install with dnf, frontend/backend config, firewall, systemctl reload

Step 3 — check config, then start

# Validate the config syntax
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
# Configuration file is valid

# Enable + start
sudo systemctl enable --now haproxy

# Status
sudo systemctl status haproxy

Step 4 — open the firewall

# firewalld (default on RHEL-family)
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

# Confirm
sudo firewall-cmd --list-services

If SELinux is enforcing, also let HAProxy bind to non-default ports if you need them: sudo setsebool -P haproxy_connect_any 1. Standard ports 80/443 don’t need this.

Step 5 — reload without dropping connections

# After editing the config
sudo haproxy -c -f /etc/haproxy/haproxy.cfg   # validate first
sudo systemctl reload haproxy                  # zero-downtime reload

Use reload, not restart — the systemd unit performs a soft-finish handover that lets in-flight connections drain on the old process while new ones go to the new one.

Common configuration patterns

  • Health checks — add check on each server line. HAProxy will poll the backend on port 80 (the listen port) and mark unhealthy backends as DOWN.
  • Sticky sessions — cookie SERVERID insert indirect nocache in the backend, plus cookie web1 on each server line.
  • TLS termination — bind *:443 ssl crt /etc/haproxy/certs/site.pem. The .pem bundles cert + key in one file.
  • Logging — point global log at 127.0.0.1 local0 and add local0.* /var/log/haproxy.log to /etc/rsyslog.d/haproxy.conf.

Frequently asked questions

Should I still use CentOS 7 for new HAProxy installs?

No — CentOS 7 reached end-of-life on June 30 2024. Use AlmaLinux 9, Rocky Linux 9, or RHEL 9 for new installs. The HAProxy install steps are identical (dnf replaces yum), and HAProxy 2.4+ is available in the base repos. If you’re still maintaining CentOS 7 servers, the same commands work — just plan a migration before the next major HAProxy upgrade.

Where should the HAProxy stats page live in production?

Never on the public-facing port. Bind it to a non-routable address (bind 127.0.0.1:8404) or a management network, and require basic auth (stats auth admin:password). Even better, put it behind a VPN or restrict it with a firewall rule. The stats page leaks backend hostnames and load info — it’s reconnaissance gold for an attacker.

How do I reload HAProxy without dropping connections?

sudo systemctl reload haproxy. The HAProxy systemd unit uses -sf (“soft” finish) to hand over to the new process while letting old connections drain. Use reload, not restart — restart kills the old process immediately and drops in-flight requests.

How do I check the config before reloading?

sudo haproxy -c -f /etc/haproxy/haproxy.cfg. The -c flag runs config-check mode. If it prints “Configuration file is valid,” you’re safe to reload. A syntax error here would block the reload anyway, but catching it first saves a failed-reload alert from your monitoring.

Related guides

  • How to Configure Nginx for a Subdirectory
  • How to Change the Default SSH Port on Linux
  • How to Check the Linux OS Name and Version from the Command Line

References

HAProxy documentation: docs.haproxy.org. HAProxy configuration manual: docs.haproxy.org/2.4/configuration.html. AlmaLinux project: almalinux.org.

TAGGED:configurationhaproxyLinuxload-balancing

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Fix MySQL CONCAT returning NULL with COALESCE or CONCAT_WS How to Handle MySQL CONCAT Returning NULL
Next Article Install HandBrake CLI on Linux with Flatpak How to Install HandBrake CLI on Linux (Flatpak)
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Disable binary logging in MySQL or MariaDB
Server Management

How to Disable Binary Logging in MySQL or MariaDB

5 Min Read
Fix broken cPanel disk quotas with the fixquotas script
Server Management

How to Fix Quotas in cPanel

5 Min Read
Nginx redirect www to non-www or vice versa
Server Management

How to Redirect www to non-www (or vice versa) in Nginx

5 Min Read
Check if Laravel scheduler is running (cron + php artisan schedule:run)
Web Development

How to Check if Laravel Scheduler Is Running (Cron + Logs)

6 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?