SimpleACME
Sign inCreate account →
Software certificate guides

HAProxy PEM deployment: validate and renew frontend certificates

Assemble HAProxy PEM files safely, validate SNI-aware frontends and distinguish graceful reloads from memory-only Runtime API certificate updates.

HAProxy can terminate TLS for several applications while those applications keep their own internal protocols and certificates. That makes the load balancer's certificate deployment a distinct operational boundary. The PEM loaded by HAProxy, the name selected through SNI, and the certificate used on a backend connection are not automatically the same thing.

This guide targets HAProxy 2.8 or later in a conventional Linux master-worker deployment with a service-manager reload procedure. It uses one HTTPS frontend for app.example.com, with a certificate deployed as a combined PEM file. Multiple-certificate frontends, containerized deployments, and Runtime API updates are discussed where their activation behavior differs. The examples are configuration patterns to validate locally, not claims of successful production testing.

Step 1: Identify where TLS terminates and which name clients request

Draw the request path before obtaining a certificate. In this example, the browser connects to HAProxy, HAProxy terminates TLS, and a backend application receives HTTP on a restricted internal address. If you require encryption to the backend as well, configure that second connection separately with certificate verification. A secure public frontend does not prove that traffic inside the network is encrypted.

Record every public hostname accepted by the frontend and how HAProxy chooses its certificate. With one certificate, the alternative names need to cover the requested service names. With several certificates, SNI selection and the default certificate matter. A test against an IP address without SNI can show the default certificate and lead you to diagnose the wrong deployment as broken.

Inspect the running service's configuration arguments and included files. HAProxy may read several configuration files or a directory, while a container may load a different path from the host's familiar /etc/haproxy/haproxy.cfg. Use the exact arguments from the running unit for validation. Also record the runtime user and how it accesses certificate files before dropping privileges.

Step 2: Request certificates through delegated DNS validation

Prepare the existing SimpleACME registration for the relevant hostname and verify its assigned challenge CNAME at the normal DNS provider. Follow the Certbot integration guide or subscriber setup instructions for automated authenticated TXT updates. Paid access enables those updates, while the ACME client requests the certificate and retains the private key on the issuing system.

This method is useful when you do not want certificate validation coupled to frontend HTTP routing. You do not need a special challenge backend or a temporary exception to authentication rules merely to renew the load balancer's certificate. The DNS-provider account token can stay out of the proxy's configuration, and the delegated record can remain in place for subsequent validations.

Decide whether to issue one certificate with several names or separate certificates per application. Shared keys simplify some deployments but increase the consequence of a key disclosure. Separate lineages make ownership clearer when applications belong to different teams. A wildcard covers qualifying names at one subdomain level; it does not cover the apex or deeper names automatically.

Keep ACME account credentials and the SimpleACME update credential away from ordinary backend applications. The component that deploys a certificate needs narrowly scoped access to the HAProxy certificate location and activation mechanism. It does not follow that every web container should be able to rewrite proxy configuration or control the load balancer's runtime socket.

Step 3: Assemble a combined PEM without exposing the private key

HAProxy's common crt file layout combines the server certificate chain and its private key in one PEM file. Use a dedicated directory such as /etc/haproxy/certs, controlled by the deployment process. On a conventional privileged startup, root ownership and mode 0600 for the combined file are appropriate. Adapt access deliberately when HAProxy runs fully unprivileged or uses a different container user.

Create the candidate in a protected staging location rather than streaming over the active file. The following example illustrates the content order and restrictive creation mode. Confirm the actual Certbot lineage path first, and retain the preceding active PEM before replacement. Do not run a command copied from an article until its destination is confirmed to be the intended certificate file.

sudo sh -c 'umask 077
  cat /etc/letsencrypt/live/app.example.com/fullchain.pem \
      /etc/letsencrypt/live/app.example.com/privkey.pem \
      > /etc/haproxy/certs/app.next.pem'
sudo openssl x509 -in /etc/haproxy/certs/app.next.pem \
  -noout -subject -issuer -dates -ext subjectAltName

Compare the public key extracted from the certificate with the public key derived from the private key. Use public-key normalization rather than an RSA modulus comparison so the method also works with elliptic-curve certificates. Check the candidate's expiry and expected names before giving it to HAProxy. A syntactically valid PEM can still contain the wrong service's certificate.

Treat the combined PEM as a private key wherever it goes. Do not upload it as an example attachment, expose it through a static directory, or include it in a public configuration repository. Certificate chains are public, but combining one with the private key changes the file's sensitivity. Backup permissions need the same care as the active certificate's permissions.

Step 4: Configure the frontend and validate the candidate configuration

The following minimal fragment illustrates native frontend termination. It is not a replacement for your full production configuration. Preserve existing logging, health checks, routing, timeouts, and backend policies. The backend address is an example private application endpoint; decide independently whether that connection also requires TLS.

frontend application_https
    bind :443 ssl crt /etc/haproxy/certs/app.pem ssl-min-ver TLSv1.2
    mode http
    default_backend application_nodes

backend application_nodes
    mode http
    server app1 10.40.0.20:8080 check

Validate the complete configuration with the installed binary and the same file arguments used by the service. Before replacing an active PEM, you can prepare a candidate configuration that references the staged candidate path and validate that full configuration. Keep that candidate file protected and review exactly which path changed; a broad search-and-replace across unrelated certificate references is risky.

sudo haproxy -c -f /etc/haproxy/haproxy.cfg

Configuration validation does not bind the production port or prove that a backend application works, but it catches many parsing and certificate-loading problems before activation. Do not accept warnings mechanically: distinguish known harmless warnings from an unexpected missing certificate or invalid bind directive. If you deploy through multiple configuration fragments, validating only one fragment may omit the references that matter.

For a certificate directory or crt-list deployment, inventory the filenames and matching rules. Avoid leaving sensitive temporary PEM files in a directory that HAProxy loads automatically, because a candidate may become an unintended additional certificate. A dedicated staging directory outside the loaded certificate set makes the activation boundary easier to reason about.

Step 5: Activate with a controlled reload and verify SNI

Use the operating system's supported graceful reload mechanism after installing the validated candidate as the active PEM. A well-configured master-worker reload allows established connections to drain while a new worker handles fresh connections. Confirm that your actual unit implements this behavior; do not assume every container's generic restart preserves long-running connections.

sudo haproxy -c -f /etc/haproxy/haproxy.cfg
sudo systemctl reload haproxy
openssl s_client -connect app.example.com:443 \
  -servername app.example.com -verify_hostname app.example.com \
  -verify_return_error -CAfile /etc/ssl/certs/ca-certificates.crt </dev/null
curl --fail --silent --show-error https://app.example.com/health -o /dev/null

Use a real harmless application health endpoint in place of /health. The TLS handshake verifies the front door, while the HTTP probe checks routing and an application response. One does not replace the other. If your health endpoint requires authentication or intentionally returns a non-success status, choose a probe whose expected behavior is documented rather than weakening the endpoint for this test.

When checking a particular load-balancer node behind DNS or another proxy, preserve the intended hostname and SNI while selecting that node's address. Otherwise you can accidentally validate a different certificate or merely recheck the healthy node chosen by DNS. Probe every node before concluding that a shared frontend name has been updated everywhere.

Review active worker state and error logs after reload. Long-lived connections may remain on an old worker for a while, which is not the same as new handshakes serving the old certificate. Monitor new connections specifically and distinguish expected draining from a failed worker startup. A rollout should have a defined observation period before old certificate backups are discarded.

Step 6: Understand Runtime API updates and preserve rollback

HAProxy's Runtime API can update an already loaded certificate through a transaction using set ssl cert and commit ssl cert. This is a useful advanced activation method, but it changes runtime memory rather than saving the certificate to disk. If you update memory only, the next restart can silently restore the old certificate from the filesystem.

Use the Runtime API only through an appropriately protected administration socket and a reviewed deployment process. Access to that socket is privileged operational access. Record the exact certificate store path used in the transaction, check the transaction result, and commit only after a successful upload. Persist the same validated PEM on disk so future reloads and restarts remain consistent with the running state.

For many installations, staged disk replacement followed by a validated graceful reload is the simpler procedure. Either strategy needs a matched preceding PEM for rollback. If activation fails, restore that file and the prior configuration reference, validate, reload, and repeat a fresh SNI-aware endpoint check. Do not change backend routing or disable certificate verification while recovering from a frontend certificate mistake.

Filter renewal hooks for the intended lineage and serialize concurrent deployments. A wildcard shared across several frontends requires an explicit fan-out plan and per-endpoint checks. Monitor the certificate actually served by each frontend, not just the newest PEM on disk. SimpleACME's TXT activity can explain the validation stage, but only your ACME client and deployment checks establish successful issuance and proxy activation.

Frequently asked questions

Why does HAProxy need a combined PEM file?

The common crt configuration loads the certificate chain and matching private key from one PEM. Other supported layouts exist, but use one deliberate model and protect any file containing the key as a secret.

Does a Runtime API update survive a restart?

Not by itself. The runtime certificate transaction updates memory. Persist the corresponding validated files on disk as part of deployment so the next process starts with the same certificate.

Why do I see the wrong certificate when testing an IP address?

The connection may omit the service's SNI name and receive the default certificate. Test with the intended hostname and explicit hostname verification while selecting the node address separately if necessary.

Does this also secure HAProxy's backend connection?

No. Frontend TLS and backend TLS are separate connections. If the internal leg requires encryption, configure its trust, expected identity, and verification explicitly rather than assuming the public certificate covers it.

Sources

HAProxy 2.8 configuration manual documents certificate and bind configuration. HAProxy Runtime API certificate transactions explains memory updates, commits, and the need to persist changes separately.

KEEP EXPLORING

A little more clarity.

ONE CNAME. A REPEATABLE WORKFLOW.

Your next certificate. A little less complicated.

Keep your DNS provider and your ACME client.
Prepare your domain before activating paid updates.

Create your account →Explore the integrations