← Start of tutorial

WIUNIX ACADEMY

HAProxy with Let’s Encrypt and validated certificate renewal

Page 2 of 5. Review the earlier steps and prerequisites before continuing.

YOUR SYSTEM. YOUR STEPS.

Where are you working?

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

Rocky Linux 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
08

LET’S BUILD

Check the selected runtime and security paths

Label only the dedicated lab tree as haproxy_var_lib_t for master config/PEM/PID access. Outgoing backend/challenge TCP ports must be permitted web types; a port owned by another SELinux service type stops this path rather than relabeling that service. Do not enable haproxy_connect_any. Source/destination address restrictions remain in the firewall; never disable SELinux.

bash

Dedicated disposable edge VM

set -eu
getenforce
sudo python3 - <<'PY'
import re,subprocess
root='/srv/academy-haproxy-tls'
pattern=re.escape(root)+'(/.*)?'
subprocess.run(['semanage','fcontext','-a','-t','haproxy_var_lib_t',pattern],check=True)
subprocess.run(['restorecon','-RF',root],check=True)
rows=subprocess.check_output(['semanage','port','-l'],text=True).splitlines()
for port in (8080,8888):
    matches=set()
    for line in rows:
        fields=line.split(None,2)
        if len(fields)!=3 or fields[1]!='tcp':continue
        for item in fields[2].replace(',',' ').split():
            bounds=item.split('-');lo=int(bounds[0]);hi=int(bounds[-1])
            if lo<=port<=hi and fields[0] not in ('unreserved_port_t','reserved_port_t','port_t'):
                matches.add(fields[0])
    if matches and not matches.issubset({'http_port_t','http_cache_port_t'}):
        raise SystemExit('Port already belongs to another SELinux service type: '+str(port))
    if not matches:subprocess.run(['semanage','port','-a','-t','http_port_t','-p','tcp',str(port)],check=True)
print('Private lab paths labeled and exact outgoing web ports reviewed')
PY
sudo matchpathcon '/srv/academy-haproxy-tls/haproxy.cfg' '/srv/academy-haproxy-tls/certs'
getsebool haproxy_connect_any
How do I know it worked?

Dedicated path labels and exact web port types are configured without changing another service type or broad connection boolean.

09

LET’S BUILD

Prove the challenge path before contacting ACME

Start the two dedicated services only after configuration validation. From an independent internet host fetch the same probe without a resolve override, on every advertised A/AAAA path. Its exact body must be returned without redirect. Other paths return308 with the fixed hostname, not a client-controlled Host. Python http.server is a minimal lab responder, loopback-only, serving a webroot containing public tokens only; use your maintained static responder for a production service.

bash

Bash on dedicated edge VM; external checks noted in text

set -eu
sudo /usr/sbin/haproxy -c -f '/srv/academy-haproxy-tls/haproxy.cfg'
sudo systemctl daemon-reload
sudo systemctl start academy-acme-webroot.service academy-haproxy.service
printf '%s\n' academy-http01-probe | sudo tee '/srv/academy-haproxy-tls/webroot/.well-known/acme-challenge/academy-probe' >/dev/null
sudo chmod 0644 '/srv/academy-haproxy-tls/webroot/.well-known/acme-challenge/academy-probe'
curl --noproxy '*' --fail --resolve 'app.example.com:80:192.0.2.10' 'http://app.example.com/.well-known/acme-challenge/academy-probe'
curl --noproxy '*' --head --resolve 'app.example.com:80:192.0.2.10' 'http://app.example.com/'
dig +short A 'app.example.com'
dig +short AAAA 'app.example.com'
How do I know it worked?

Probe returns academy-http01-probe and ordinary HTTP returns308 to the fixed HTTPS hostname.

10

LET’S BUILD

Prove public HTTP-01 from outside the edge

Run this on an independent internet host with existing Python 3 and curl. It checks every IPv4 returned by that host’s resolver, refuses an AAAA path not supported by this IPv4-only recipe and requires the exact token bytes. Verify authoritative DNS separately; one resolver does not prove global propagation. The final ordinary request must return 308 to the fixed HTTPS hostname.

bash

Independent internet host; not the edge VM

set -eu
python3 - <<'PY'
import socket,subprocess
domain='app.example.com'
addresses={(x[0],x[4][0]) for x in socket.getaddrinfo(domain,80,type=socket.SOCK_STREAM)}
if any(family==socket.AF_INET6 for family,ip in addresses):
    raise SystemExit('AAAA exists: this IPv4-only lab needs a separately reviewed IPv6 path or no AAAA')
if not addresses:raise SystemExit('No public IPv4 address resolved')
for family,ip in sorted(addresses):
    result=subprocess.run(['curl','--noproxy','*','--fail','--silent','--show-error','--max-time','15',
        '--write-out','\n%{http_code}','--resolve',domain+':80:'+ip,'http://'+domain+'/.well-known/acme-challenge/academy-probe'],check=True,capture_output=True)
    body,status=result.stdout.rsplit(b'\n',1)
    if status!=b'200' or body!=b'academy-http01-probe\n':raise SystemExit('Wrong challenge body from '+ip)
    print(ip+': exact public challenge body OK')
PY
curl --noproxy '*' --head --max-time 15 'http://app.example.com/'
How do I know it worked?

Each resolved public IPv4 returns the exact token body without redirect; ordinary HTTP uses the fixed HTTPS location.

Resolve DNS, IPv6 and CA prerequisites

All public A/AAAA addresses must reach this responder on port80; IPv6 is preferred and a wrong AAAA response is not reliably rescued by IPv4. This IPv4-only example requires no AAAA record; an IPv6 deployment needs an explicit IPv6 bind and independently tested routing. Check authoritative DNS, CAA permissions, DNSSEC errors, outbound HTTPS443 to ACME, system clock and provider/NAT/firewall reachability before ordering. HTTP-01 cannot issue wildcard names.

The next commands contact a public CA and may register an account after you review its terms. Use your real owned hostname. No issuance/account registration was performed for this article. Failures remain failures; do not suppress exit status, retry production orders blindly or promise a fixed certificate lifetime. Consult current rate limits and honor Retry-After.

11

LET’S BUILD

Try staging in a separate ACME tree

Review the CA terms interactively. Enter a monitored email in Certbot itself, never in reader settings. Staging uses separate accounts and untrusted certificates; nothing from this directory is deployed. A successful dry run is a real CA/network operation and is not proved by this page preview.

bash

Bash on dedicated edge VM; external checks noted in text

sudo /usr/bin/certbot certonly --dry-run --webroot -w '/srv/academy-haproxy-tls/webroot' -d 'app.example.com' --cert-name 'app.example.com' \
  --config-dir '/srv/academy-haproxy-tls/acme/staging-config' \
  --work-dir '/srv/academy-haproxy-tls/acme/staging-work' \
  --logs-dir '/srv/academy-haproxy-tls/acme/staging-logs'
How do I know it worked?

Certbot reports a successful simulated issuance; staging material never enters the served PEM.

12

LET’S BUILD

Request the production certificate once

Proceed only after the external probe and staging succeed. Keep Certbot output and its failure status. Use a single hostname and the explicit cert-name so the protected lineage is predictable. This certonly command does not edit HAProxy.

bash

Bash on dedicated edge VM; external checks noted in text

sudo /usr/bin/certbot certonly --webroot -w '/srv/academy-haproxy-tls/webroot' -d 'app.example.com' --cert-name 'app.example.com' \
  --config-dir '/srv/academy-haproxy-tls/acme/config' \
  --work-dir '/srv/academy-haproxy-tls/acme/work' \
  --logs-dir '/srv/academy-haproxy-tls/acme/logs'
sudo /usr/bin/certbot certificates --config-dir '/srv/academy-haproxy-tls/acme/config' --work-dir '/srv/academy-haproxy-tls/acme/work' --logs-dir '/srv/academy-haproxy-tls/acme/logs'
How do I know it worked?

The named production lineage contains cert.pem, chain.pem, fullchain.pem and protected privkey.pem for the real domain.

Explore all tutorials ↗