Illustrative WIUNIX Academy IT engineering workspace with server/network equipment and an instructional board: HAProxy with Let’s Encrypt and validated certificate renewal

WIUNIX ACADEMY

HAProxy with Let’s Encrypt and validated certificate renewal

Balance two private backends behind HAProxy TLS on DEB, RHEL or Arch-family Linux; preserve HTTP-01 and validate certificate deployment, renewal and recovery.

Intermediate65 min readUpdated
Make this guide yours

YOUR SYSTEM. YOUR STEPS.

Where are you working?

Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.

RHEL 10.2Reviewed against official documentation ·

USE YOUR OWN VALUES

Configure this tutorial

Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.

Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.

Set values for my environment7 editable values

THE OUTCOME

What will you have at the end?

Serve app.example.com through two healthy backends with validated recoverable TLS deployment.

01HTTP-01Internet TCP80 → 192.0.2.10:80 → 127.0.0.1:8888 → webroot
02HTTPSapp.example.com TCP443 → HAProxy → 10.77.0.21 / 10.77.0.22 : 8080
Supported operating systems and versions

Linux paths documented 2026-11-05; historical container fixtures do not certify the current hook, public ACME or every OS installation.

Before you begin

  • Fresh disposable sudo/systemd edge VM with existing Bash, ip and ss, independent console, owned hostname and DNS/firewall administration.
  • Two private ready backends serving /health/ready for the same Host; unused /srv/academy-haproxy-tls and listener ports.
  • Independent internet host with existing curl/Python 3 for public ingress checks; reader settings accept no keys or passwords.

A TLS edge with a recoverable certificate path

Build one HAProxy edge for app.example.com, forwarding to 10.77.0.21 and 10.77.0.22 on 8080. Keep HTTP-01 available while all other HTTP requests redirect to HTTPS. A certificate renewal must pass key, chain, name and proxy validation before a graceful reload.

This is an intermediate fresh-VM exercise, about 65 minutes plus DNS/ACME time. One edge is a single point of failure. No session persistence, application data replication or high availability is implied. Private HTTP backends require an isolated trusted network; use authenticated backend TLS across untrusted networks.

Separate the public edge from the challenge responder

Clients reach local address 192.0.2.10 on TCP80/443, directly or through deliberate NAT. Public DNS must point to the real public ingress, not blindly to that local address. The example domain and documentation IPv4 cannot issue a certificate: replace them first. The public challenge port is always80; 8888 is loopback-only behind HAProxy.

Only the challenge prefix reaches the static webroot. TLS traffic is round-robin balanced with a readiness check. HAProxy replaces incoming proxy headers; applications trust these headers only from this edge and reject direct internet access. A CDN or upstream proxy changes the trust boundary and is outside this direct-edge recipe.

01

LET’S BUILD

Check ownership, addresses and existing listeners

Run on a new disposable edge VM, not a production HAProxy host. The selected local IPv4 must already belong to this VM; TCP80/443 and the loopback challenge port must be free. Stop if HAProxy, Certbot state, one of the named units or /srv/academy-haproxy-tls already exists. Preserve the SSH console and firewall owner. Apply only reviewed TCP80/443 ingress and edge-to-backend rules through that owner; this guide does not overwrite a firewall.

bash

Bash on dedicated edge VM; external checks noted in text

set -eu
cat /etc/os-release
test "$(ps -p 1 -o comm=)" = systemd
command -v ip >/dev/null
command -v ss >/dev/null
ip -br address
sudo ss -lntup
for path in '/srv/academy-haproxy-tls' /etc/haproxy /etc/letsencrypt /var/lib/letsencrypt /var/log/letsencrypt; do
  if sudo test -e "$path" || sudo test -L "$path"; then echo "Existing state: $path; STOP" >&2; exit 1; fi
done
for name in haproxy certbot; do
  if command -v "$name" >/dev/null 2>&1; then echo "Existing executable: $name; STOP" >&2; exit 1; fi
done
states=$(sudo systemctl show haproxy.service certbot.service certbot.timer certbot-renew.service certbot-renew.timer academy-haproxy.service academy-acme-webroot.service academy-certbot.service academy-certbot.timer -p LoadState --value)
for state in $states; do
  test "$state" = not-found || { echo 'Existing or masked service/timer; STOP' >&2; exit 1; }
done
How do I know it worked?

A fresh edge has no conflicting service/state; its local address and the reviewed network path are known.

02

LET’S BUILD

Use signed distribution packages

Review signed package candidates and security coverage. DEB uses distribution HAProxy/Certbot; EL 10.2/9.8 uses AppStream HAProxy and community EPEL Certbot outside Red Hat commercial support. Arch/Manjaro use their own repositories and a full upgrade only on this fresh disposable VM.

After the prior check proves all named vendor units absent, mask only the default service/timer names before package installation to prevent automatic sample service or renewal start. Distinct academy units remain usable. Never apply these masks to an existing/shared host. The guide retains Certbot webroot/deploy hooks; every environment uses its actual absolute executable because interactive PATH, sudo and systemd differ.

bash

Bash on dedicated edge VM; external checks noted in text

set -eu
. /etc/os-release
test "$ID" = 'rhel'
test "$VERSION_ID" = '10.2'
sudo systemctl mask haproxy.service certbot-renew.service certbot-renew.timer
sudo subscription-manager repos --enable codeready-builder-for-rhel-10-x86_64-rpms
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm
sudo dnf info haproxy certbot python3
sudo dnf install haproxy certbot python3 openssl ca-certificates curl bind-utils nano shadow-utils policycoreutils-python-utils
rpm -q haproxy certbot python3
sudo /usr/sbin/haproxy -vv
/usr/bin/certbot --version
sudo /usr/sbin/haproxy -vv | grep -F '+SYSTEMD'
test -f /etc/pki/tls/certs/ca-bundle.crt
How do I know it worked?

Package channels/versions are recorded; the newly introduced vendor units remain masked and HAProxy supports systemd.

03

LET’S BUILD

Create distinct public and protected directories

Create one new root under an existing root-owned non-writable ancestry, refusing every symlink and existing root/worker identity. Only the public webroot is readable by the dedicated academy-acme responder; certificate/account directories remain root-only. The non-chrooted HAProxy master reads PEMs as root before workers drop to haproxy. Explicit modes prevent restrictive umask from making public token files unreadable.

A temporary bind check verifies the actual local frontend IPv4 and free listener ports. It does not reserve them until service start. A second run is not a recovery procedure; investigate partial state and use a fresh disposable VM.

bash

Bash on dedicated edge VM; external checks noted in text

sudo python3 - <<'PY'
from pathlib import Path
import os,stat,pwd,grp,subprocess,socket
r=Path('/srv/academy-haproxy-tls')
if not r.is_absolute() or str(r) in ('/','/srv','/etc','/opt','/tmp','/var'):
    raise SystemExit('Choose a new dedicated absolute child path')
for p in reversed(r.parents):
    s=p.lstat()
    if not stat.S_ISDIR(s.st_mode) or s.st_uid!=0 or s.st_mode & 0o022:
        raise SystemExit('Unsafe parent: '+str(p))
for fn in (pwd.getpwnam,grp.getgrnam):
    try:fn('academy-acme')
    except KeyError:pass
    else:raise SystemExit('Responder identity already exists; use a fresh VM')
pwd.getpwnam('haproxy');grp.getgrnam('haproxy')
for address,port in [('192.0.2.10',80),('192.0.2.10',443),('127.0.0.1',8888)]:
    with socket.socket() as s:s.bind((address,port))
r.mkdir(mode=0o755);os.chmod(r,0o755)
subprocess.run(['useradd','--system','--user-group','--no-create-home','--shell','/usr/sbin/nologin','academy-acme'],check=True)
for name,mode in [('webroot',0o755),('webroot/.well-known',0o755),('webroot/.well-known/acme-challenge',0o755),('certs',0o700),('acme',0o700)]:
    p=r/name;p.mkdir(mode=mode);os.chmod(p,mode)
for name in ('config','work','logs','staging-config','staging-work','staging-logs'):
    p=r/'acme'/name;p.mkdir(mode=0o700);os.chmod(p,0o700)
print('New public webroot, protected private directories and dedicated responder created')
PY
How do I know it worked?

The dedicated academy-acme responder can read public tokens; certificate/account directories remain 0700 and private.

04

LET’S BUILD

Open the HTTP bootstrap and service files

Create only these new files. Paste each following panel into its matching filename; do not execute file contents as shell. The bootstrap intentionally serves no application on HTTPS until issuance succeeds. Keep the temporary redirect phase within a planned setup window.

bash

Bash on dedicated edge VM; external checks noted in text

set -eu
test ! -e '/srv/academy-haproxy-tls/haproxy.cfg'
test ! -L '/srv/academy-haproxy-tls/haproxy.cfg'
sudo install -m 0644 /dev/null '/srv/academy-haproxy-tls/haproxy.cfg'
test ! -e /etc/systemd/system/academy-haproxy.service
test ! -L /etc/systemd/system/academy-haproxy.service
sudo install -m 0644 /dev/null /etc/systemd/system/academy-haproxy.service
test ! -e /etc/systemd/system/academy-acme-webroot.service
test ! -L /etc/systemd/system/academy-acme-webroot.service
sudo install -m 0644 /dev/null /etc/systemd/system/academy-acme-webroot.service
sudo nano '/srv/academy-haproxy-tls/haproxy.cfg' /etc/systemd/system/academy-haproxy.service /etc/systemd/system/academy-acme-webroot.service
How do I know it worked?

Three empty new files are open; the next three panels supply their complete contents.

05

LET’S BUILD

HTTP-only bootstrap configuration

File contents. Save exactly at the displayed filename.

text · /srv/academy-haproxy-tls/haproxy.cfg

File on the dedicated edge VM

global
  log stdout format raw local0
  user haproxy
  group haproxy
  ssl-default-bind-options ssl-min-ver TLSv1.2

defaults
  log global
  mode http
  option httplog
  timeout connect 5s
  timeout client 30s
  timeout server 30s
  timeout http-request 10s

frontend public_http
  bind 192.0.2.10:80
  acl known_host hdr(host) -i app.example.com app.example.com:80
  http-request deny deny_status 421 unless known_host
  acl acme_path path_beg /.well-known/acme-challenge/
  http-request redirect prefix https://app.example.com code 308 unless acme_path
  use_backend acme_webroot if acme_path

backend acme_webroot
  server challenge 127.0.0.1:8888 check
How do I know it worked?

The saved file matches this panel; no key material is included.

06

LET’S BUILD

HAProxy master-worker service

File contents. Save exactly at the displayed filename.

ini · /etc/systemd/system/academy-haproxy.service

File on the dedicated edge VM

[Unit]
Description=Academy isolated HAProxy listener
After=network-online.target academy-acme-webroot.service
Requires=academy-acme-webroot.service
Wants=network-online.target

[Service]
Type=notify
ExecStart=/usr/sbin/haproxy -Ws -f /srv/academy-haproxy-tls/haproxy.cfg -p /srv/academy-haproxy-tls/haproxy.pid
ExecReload=/usr/sbin/haproxy -c -f /srv/academy-haproxy-tls/haproxy.cfg
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=on-failure

[Install]
WantedBy=multi-user.target
How do I know it worked?

The saved file matches this panel; no key material is included.

07

LET’S BUILD

Loopback static responder

File contents. Save exactly at the displayed filename.

ini · /etc/systemd/system/academy-acme-webroot.service

File on the dedicated edge VM

[Unit]
Description=Academy HTTP-01 static webroot
After=network.target

[Service]
User=academy-acme
Group=academy-acme
ExecStart=/usr/bin/python3 -m http.server 8888 --bind 127.0.0.1 --directory /srv/academy-haproxy-tls/webroot
Restart=on-failure
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true

[Install]
WantedBy=multi-user.target
How do I know it worked?

The saved file matches this panel; no key material is included.

Explore all tutorials ↗