23.4. Enabling HTTPS

This section explains the certificate machinery the practice sites already use, adds Apache's TLS listeners for its two names, and then automates the whole lifecycle for a third name with ACME: issuance, renewal on a timer, and deployment into the running server.

23.4.1. Certificate Names, Chains, and Private Key Permissions

A TLS client does something very specific when it validates a connection: it takes the leaf certificate the server presented, walks the issuer chain upward until it reaches a certificate it already trusts, and checks that every step is allowed to sign the next. Three facts follow, and every HTTPS misconfiguration is one of them ignored:

  • The name must be in the certificate's Subject Alternative Name. Modern clients ignore the common name entirely. One certificate can list many names - the lab's wildcard lists *.handbook.test and handbook.test in one SAN extension, which is why every something.handbook.test site can share it.
  • The server must present the chain the client cannot build itself. Clients trust roots, servers hold leaves, and the intermediate in between must be served. That is what the .fullchain.pem files exist for.
  • The private key is the only secret. Certificates are public documents; the key file's permissions are the whole of key protection.

The practice certificate hierarchy

Figure 23.3. Who signs, who serves, who trusts. The root signs the issuing CA, which signs the three leaves; servers always present leaf plus intermediate, and clients verify upward to a root already in their own store. The ACME exercise chain on the right is separate and ephemeral.

The lab's hierarchy is small enough to verify by hand, with the files still in john's workspace. On web1, as john:

$ openssl verify -CAfile ~/debian-handbook/web-services/ca/root.crt -untrusted ~/debian-handbook/web-services/ca/intermediate.crt ~/debian-handbook/web-services/ca/www.crt ~/debian-handbook/web-services/ca/shop.crt ~/debian-handbook/web-services/ca/wildcard.crt
/home/john/debian-handbook/web-services/ca/www.crt: OK
/home/john/debian-handbook/web-services/ca/shop.crt: OK
/home/john/debian-handbook/web-services/ca/wildcard.crt: OK

-CAfile supplies the trust anchor and -untrusted the intermediate the validator may use to reach it. Drop the intermediate and the exact failure a misconfigured server produces appears, as an exit status of 2:

$ openssl verify -CAfile ~/debian-handbook/web-services/ca/root.crt ~/debian-handbook/web-services/ca/www.crt
CN=www.handbook.test, O=Handbook Lab
error 20 at 0 depth lookup: unable to get local issuer certificate
error /home/john/debian-handbook/web-services/ca/www.crt: verification failed

The certificate itself is valid; the chain to the root is simply not available. A server that presents only its leaf makes every client report exactly this. Inspect what a certificate actually claims, on web1, as john:

$ openssl x509 -in ~/debian-handbook/web-services/ca/wildcard.crt -noout -subject -issuer -ext subjectAltName
subject=CN=*.handbook.test, O=Handbook Lab
issuer=CN=Handbook Lab Issuing CA, O=Handbook Lab
X509v3 Subject Alternative Name:
    DNS:*.handbook.test, DNS:handbook.test

The openssl subcommands used in this chapter:

Invocation Description
verify -CAfile f -untrusted g cert... validate certificates against the root f, allowing the untrusted intermediate g in the chain
x509 -in cert -noout -subject -issuer -ext subjectAltName print a certificate's subject, issuer, and SAN without the PEM body
x509 -noout -serial -dates print the serial and validity dates of a certificate read from standard input
s_client -connect host:port -servername name open a TLS connection and print the negotiated session; -servername sends the SNI name
s_client -showcerts print every certificate the server presents, in order

Apache's TLS listeners now get the same material the Nginx site already uses. The two files mirror the HTTP pair from Section 23.2.2. File contents for web1, fixtures/apache/www-ssl.conf:

<VirtualHost *:443>
    ServerName www.handbook.test
    ServerAlias handbook.test
    DocumentRoot /var/www/www.handbook.test

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/www.handbook.test.crt
    SSLCertificateKeyFile /etc/ssl/private/www.handbook.test.key
    SSLCertificateChainFile /etc/ssl/certs/handbook-intermediate.crt
    SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
    SSLCipherSuite HIGH:!aNULL:!MD5
    Header always set Strict-Transport-Security "max-age=31536000"

    <Directory /var/www/www.handbook.test>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/www-error.log
    CustomLog ${APACHE_LOG_DIR}/www-access.log combined
</VirtualHost>

And fixtures/apache/shop-ssl.conf:

<VirtualHost *:443>
    ServerName shop.handbook.test
    DocumentRoot /var/www/shop.handbook.test

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/shop.handbook.test.crt
    SSLCertificateKeyFile /etc/ssl/private/shop.handbook.test.key
    SSLCertificateChainFile /etc/ssl/certs/handbook-intermediate.crt
    SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1

    <Directory /var/www/shop.handbook.test>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    <Directory /var/www/shop.handbook.test/private>
        Require all denied
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/shop-error.log
    CustomLog ${APACHE_LOG_DIR}/shop-access.log combined
</VirtualHost>

Three details are load-bearing. SSLCertificateFile points at the leaf alone while SSLCertificateChainFile adds the intermediate - since Apache 2.4.8 the alternative is one file holding leaf plus chain in SSLCertificateFile, which is exactly what the Nginx side does with its fullchain; both forms are current. The SSLProtocol line disables everything except TLS 1.2 and 1.3; Section 23.4.4 verifies that at the wire. Header always set adds HSTS to every response, errors included - the always matters, because without it locally generated error pages would ship without the header.

Install the certificate material and both sites, on web1, as john:

$ sudo install -m 0644 ~/debian-handbook/web-services/ca/www.crt /etc/ssl/certs/www.handbook.test.crt
$ sudo install -m 0640 -g www-data ~/debian-handbook/web-services/ca/www.key /etc/ssl/private/www.handbook.test.key
$ sudo install -m 0644 ~/debian-handbook/web-services/ca/shop.crt /etc/ssl/certs/shop.handbook.test.crt
$ sudo install -m 0640 -g www-data ~/debian-handbook/web-services/ca/shop.key /etc/ssl/private/shop.handbook.test.key
$ sudo install -m 0644 ~/debian-handbook/web-services/ca/intermediate.crt /etc/ssl/certs/handbook-intermediate.crt
$ sudo install -m 0644 fixtures/apache/www-ssl.conf /etc/apache2/sites-available/www-ssl.conf
$ sudo install -m 0644 fixtures/apache/shop-ssl.conf /etc/apache2/sites-available/shop-ssl.conf

Every command is silent. Enable both sites with sudo a2ensite www-ssl shop-ssl, which prints one Enabling site block per name in the format captured in Section 23.2.2, then validate with sudo apache2ctl configtest and activate with sudo systemctl reload apache2, exactly as in Sections 23.2.3 and 23.2.4.

Verify through the client's eyes, on client1, as john:

$ curl -sS https://www.handbook.test/
<!doctype html>
<html lang="en"><head><meta charset="utf-8">
<title>Apache www site</title></head>
<body><h1>www.handbook.test</h1>
<p>Static content served by Apache HTTP Server.</p>
</body></html>

The redirect from Section 23.2.4 now has its target. The shop's private directory travels with its policy - the Require all denied block from Section 23.2.3 applies to the TLS vhost because it is repeated there:

$ curl -sS -o /dev/null -w '%{http_code}\n' https://shop.handbook.test/private/
403

The same page over plain HTTP from Section 23.2.2 is gone, because the port 80 vhost now redirects. Check what the wire actually presents - on client1, as john:

$ timeout 8 openssl s_client -connect www.handbook.test:443 -servername www.handbook.test -showcerts </dev/null 2>/dev/null | grep -c 'BEGIN CERTIFICATE'
2

Two certificates: leaf and intermediate, never the root. The pipeline is one logical operation - s_client prints the whole served chain, and the count of BEGIN CERTIFICATE lines is the result. Its three shell pieces each do one job: </dev/null gives the probe an immediately empty standard input, timeout 8 bounds the run - s_client is an interactive tool that otherwise waits on the TLS session until the server closes it - and 2>/dev/null discards the handshake summary s_client writes to standard error, so the count is the only thing printed. A count of 1 here is the smoking gun of the missing-chain failure verified earlier.

Key permissions are the third leg. On web2, as john:

$ sudo stat -c '%a %U:%G %n' /etc/ssl/private/handbook-wildcard.key
640 root:www-data /etc/ssl/private/handbook-wildcard.key

The mode is deliberate on every host in this chapter: the file belongs to root, the group is the account the server reads keys as, and no one else can read it. Two reinforcing details: /etc/ssl/private itself is root:ssl-cert 0710, so even listing the directory needs membership, and the server opens keys once at start as root before dropping to www-data - which is why the group readable bit suffices and world access never needs to exist. The Apache keys on web1 were installed with the same install -m 0640 -g www-data shape.

23.4.2. ACME Issuance and Challenge Requirements

A private hierarchy is a fine thing for names that only your own clients see, but a public name needs a certificate that strangers' browsers already trust, without anyone copying files to them. ACME - the protocol behind Let's Encrypt and other public CAs - automates exactly that: an agent on your server proves control of a name, the CA issues a short-lived certificate, and the same agent renews it before it expires. Debian's agent is certbot.

The proof of control is a challenge. The three kinds in common use:

Challenge What the CA does What your host needs Typical use
HTTP-01 fetch a token from http://name/.well-known/acme-challenge/ the name resolves publicly to this host, port 80 reachable from the Internet single names, the default
DNS-01 look for a token in a TXT record permission to change the name's DNS zone wildcard names, hosts behind filters
TLS-ALPN-01 connect on port 443 and read the token from the handshake port 443 reachable, no other TLS service conflicting hosts where port 80 is impractical

For a normal public site the procedure is one command. Install the agent with its Apache integration plugin on the web host, as john - sudo apt install certbot python3-certbot-apache - then issue against the real ACME directory with sudo certbot --apache -d www.example.net. Certbot asks for a contact email, shows the terms of service for acceptance, performs the HTTP-01 challenge by briefly answering on port 80, installs the certificate into the vhost it found, and offers to redirect all HTTP traffic to HTTPS. Those prompts and the resulting messages are certbot's normal interactive behavior; on a host with a public name and open port 80 the flow needs nothing else. Nginx hosts get the same with python3-certbot-nginx and certbot --nginx; a server you would rather not have reconfigured gets certbot certonly --webroot -w /var/www/... -d name, which only writes challenge files into a directory you name.

The practice network is not publicly reachable, so this chapter exercises the identical flow against Pebble, the packaged ACME v2 test server, on web1's loopback. Every command below is a real certbot invocation; only the endpoint and port values are lab-specific, and the text says so at each step. Install it on web1, as john, with sudo apt install pebble.

Pebble needs a configuration and a TLS certificate for its own HTTPS endpoint; both are throwaway. File contents for web1, fixtures/acme/pebble-config.json:

{
  "pebble": {
    "listenAddress": "127.0.0.1:14000",
    "managementListenAddress": "127.0.0.1:15000",
    "certificate": "/etc/pebble/localhost.crt",
    "privateKey": "/etc/pebble/localhost.key",
    "httpPort": 5002,
    "tlsPort": 5001,
    "ocspResponderURL": "",
    "externalAccountBindingRequired": false,
    "domainBlocklist": [],
    "retryAfter": {
      "authz": 1,
      "order": 1
    },
    "certificateValidityPeriod": 7776000
  }
}

And the service - file contents for web1, fixtures/acme/pebble.service:

[Unit]
Description=Pebble ACME test server
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/pebble -config /etc/pebble/pebble-config.json
Restart=on-failure
NoNewPrivileges=yes
PrivateTmp=yes

[Install]
WantedBy=multi-user.target

Set up the endpoint certificate, the configuration, and the service, on web1, as john. The directory first:

$ sudo install -d -m 0755 /etc/pebble

Silent, like every install in this chapter. The endpoint certificate is a throwaway self-signed one covering localhost and the loopback address:

$ sudo openssl req -x509 -newkey rsa:2048 -nodes -sha256 -days 2 -subj /CN=localhost -addext subjectAltName=DNS:localhost,IP:127.0.0.1 -keyout /etc/pebble/localhost.key -out /etc/pebble/localhost.crt
.....+...+.+...+........+...+.......+.....+++++++++++++++++++++++++++++++++++++++*..+..+.+...+.....+.+++++++++++++++++++++++++++++++++++++++*.+..+..........+..+...+.......++++++
-----

Selected output; the command prints only OpenSSL's RSA key-generation progress - two long lines, of which the tail is shown - and writes the certificate and key to the named files, exactly like the CA script in Section 23.3.1. Its key gets restricted afterwards:

$ sudo chmod 0600 /etc/pebble/localhost.key

Then the configuration and the service:

$ sudo install -m 0644 fixtures/acme/pebble-config.json /etc/pebble/pebble-config.json
$ sudo install -m 0644 fixtures/acme/pebble.service /etc/systemd/system/pebble.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now pebble

The two install commands and the daemon-reload are silent; the two-day validity of the endpoint certificate is harmless for a disposable test listener. systemctl enable --now creates the boot symlink and starts the unit, printing a Created symlink line in the format captured in Section 23.5.1.

The exercise name must resolve to the machine running the challenge server, which on the lab means a hosts entry - on web1, as john:

$ echo '127.0.0.1 acme.handbook.test' | sudo tee -a /etc/hosts > /dev/null

tee -a appends the line; the redirect keeps its echo out of the terminal, so the command prints nothing. Confirm the test server's directory answers, on web1, as john:

$ sudo curl --cacert /etc/pebble/localhost.crt -sS https://localhost:14000/dir
{
   "keyChange": "https://localhost:14000/rollover-account-key",
   "meta": {
      "externalAccountRequired": false,
      "termsOfService": "data:text/plain,Do%20what%20thou%20wilt"
   },
   "newAccount": "https://localhost:14000/sign-me-up",
   "newNonce": "https://localhost:14000/nonce-plz",
   "newOrder": "https://localhost:14000/order-plz",
   "renewalInfo": "https://localhost:14000/draft-ietf-acme-ari-03/renewalInfo",
   "revokeCert": "https://localhost:14000/revoke-cert"
}

Those resource URLs are what an ACME client discovers on every server, test or public. Now fail a challenge on purpose, because the failure shape is the useful part. Pebble validates HTTP-01 on its configured httpPort 5002; the command below deliberately starts certbot's temporary webserver on 5003 instead, on web1, as john:

$ sudo certbot certonly --standalone --http-01-port 5003 --server https://127.0.0.1:14000/dir --no-verify-ssl --agree-tos --register-unsafely-without-email -d acme.handbook.test
Account registered.
Requesting a certificate for acme.handbook.test

Certbot failed to authenticate some domains (authenticator: standalone). The Certificate Authority reported these problems:
  Domain: acme.handbook.test
  Type:   connection
  Detail: Get "http://acme.handbook.test:5002/.well-known/acme-challenge/uUg7vcJvGAjCyOx0ZDcqH4YlR95Xs5kILt9BHv50tZ0": dial tcp 127.0.0.1:5002: connect: connection refused

Hint: The Certificate Authority failed to download the challenge files from the temporary standalone webserver started by Certbot on port 5003. Ensure that the listed domains point to this machine and it can accept inbound connections from the internet.

The transcript shows standard output only: in these test-server runs, certbot also writes its debug-log location and Python's InsecureRequestWarning lines to standard error, for the --no-verify-ssl reason labeled below.

Read the error like an operator: the CA dialed the validation port and nothing answered, while certbot's server sat on a different one. The public equivalent of this failure is a firewall dropping port 80, a name resolving to the wrong address, or another server already holding port 80 - the hint names all three. Two lab-only flags appear here and deserve their labels: --no-verify-ssl because Pebble's own endpoint uses the throwaway certificate, and --register-unsafely-without-email because the exercise registers no contact; against a public CA you provide an email and accept the terms interactively. The first run on a host also prints Account registered. as shown.

The same command against the correct port succeeds, on web1, as john:

$ sudo certbot certonly --standalone --http-01-port 5002 --server https://127.0.0.1:14000/dir --no-verify-ssl --agree-tos --register-unsafely-without-email -d acme.handbook.test
Requesting a certificate for acme.handbook.test

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/acme.handbook.test/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/acme.handbook.test/privkey.pem
This certificate expires on 2027-02-20.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Selected output; certbot's closing donation banner is omitted. The live directory holds fullchain.pem and privkey.pem - the same leaf-plus-intermediate and key pair that the private hierarchy produced, in the same shapes a web server wants. See what certbot now tracks, on web1, as john:

$ sudo certbot certificates

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: acme.handbook.test
    Serial Number: 195263d6d620dad5
    Key Type: ECDSA
    Domains: acme.handbook.test
    Expiry Date: 2027-02-20 17:04:37+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/acme.handbook.test/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/acme.handbook.test/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The certbot invocations used here:

Invocation Description
certbot certonly --standalone -d name obtain a certificate with certbot's temporary webserver; nothing in the running server is modified
certbot certonly --webroot -w dir -d name place challenge files in an existing site's document root
certbot --apache / certbot --nginx obtain and install into the detected server configuration
--http-01-port port the port the temporary webserver binds (a public CA validates on port 80)
--server URL use this ACME directory instead of the default public one
--deploy-hook cmd run cmd after any successful issuance or renewal
certbot certificates list tracked certificates, expiry, and file paths
certbot renew attempt renewal of every certificate that is due; skips the rest
certbot renew --dry-run rehearse renewal against the staging environment; changes nothing
certbot renew --force-renewal renew even when not due - for testing the pipeline

23.4.3. Automated Renewal and Service Reloads

A certificate that needs a human every ninety days will eventually lapse, so renewal must be a scheduled, unattended, self-checking routine. The Debian certbot package ships exactly that: a systemd timer, not a cron entry, following the pattern of Chapter 10. Look at both units, on web1, as john. Each output's first line is a # comment from systemctl cat naming the file it printed - part of the output, not a root prompt:

$ systemctl cat certbot.timer
# /usr/lib/systemd/system/certbot.timer
[Unit]
Description=Run certbot twice daily

[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=43200
Persistent=true

[Install]
WantedBy=timers.target
$ systemctl cat certbot.service
# /usr/lib/systemd/system/certbot.service
[Unit]
Description=Certbot
Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
Documentation=https://certbot.eff.org/docs
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot -q renew --no-random-sleep-on-renew
PrivateTmp=true

Twice a day, offset by up to twelve hours of randomization so a fleet of hosts does not hit the CA in lockstep, the service runs certbot -q renew - quiet, and renewing only certificates that are due, which is what makes running it four times a day harmless. Check the schedule as your unit sees it:

$ systemctl list-timers certbot.timer --no-pager
NEXT                        LEFT LAST PASSED UNIT          ACTIVATES
Mon 2026-11-23 01:35:43 UTC   8h    -      - certbot.timer certbot.service

1 timers listed.
Pass --all to see loaded but inactive timers, too.

The one piece certbot cannot know is your web server: a renewed certificate on disk does nothing until the server reloads and reads it. The clean mechanism is a deploy hook - a command certbot runs after each successful issuance or renewal. File contents for web1, fixtures/acme/deploy-acme.sh:

#!/bin/sh
set -eu

install -m 0644 /etc/letsencrypt/live/acme.handbook.test/fullchain.pem \
  /etc/ssl/certs/acme.handbook.test.fullchain.pem
install -m 0640 -g www-data /etc/letsencrypt/live/acme.handbook.test/privkey.pem \
  /etc/ssl/private/acme.handbook.test.key
systemctl reload apache2

It copies the fresh pair into /etc/ssl with the key permissions of Section 23.4.1 and reloads Apache - the same validate-free reload is safe here because the running configuration does not change, only the files it points at. Install the hook and a vhost that uses the issued certificate. The site's single page comes first - file contents for web1, fixtures/static/acme-index.html:

<!doctype html>
<html lang="en"><head><meta charset="utf-8">
<title>ACME test site</title></head>
<body><h1>acme.handbook.test</h1>
<p>Certificate issued by the local Pebble ACME test server.</p>
</body></html>

And the vhost itself - file contents for web1, fixtures/apache/acme-ssl.conf:

<VirtualHost *:443>
    ServerName acme.handbook.test
    DocumentRoot /var/www/acme.handbook.test

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/acme.handbook.test.fullchain.pem
    SSLCertificateKeyFile /etc/ssl/private/acme.handbook.test.key

    <Directory /var/www/acme.handbook.test>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/acme-error.log
    CustomLog ${APACHE_LOG_DIR}/acme-access.log combined
</VirtualHost>

This vhost points SSLCertificateFile at the fullchain file directly - the one-file form mentioned in Section 23.4.1. Deploy the content, the site, and the hook, on web1, as john - every install in the sequence is silent:

$ sudo install -d -o www-data -g www-data /var/www/acme.handbook.test
$ sudo install -m 0644 -o www-data -g www-data fixtures/static/acme-index.html /var/www/acme.handbook.test/index.html
$ sudo install -m 0644 fixtures/apache/acme-ssl.conf /etc/apache2/sites-available/acme-ssl.conf
$ sudo a2ensite acme-ssl
Enabling site acme-ssl.
To activate the new configuration, you need to run:
  systemctl reload apache2
$ sudo install -m 0755 fixtures/acme/deploy-acme.sh /usr/local/sbin/handbook-deploy-acme
$ sudo /usr/local/sbin/handbook-deploy-acme

The hook run prints nothing - both install calls and the reload are silent - and leaves the certificate pair in place. Validate:

$ sudo apache2ctl configtest
Syntax OK

Now force a renewal to prove the whole pipeline - timer, renewal, hook, reload - end to end, on web1, as john:

$ sudo certbot renew --force-renewal --http-01-port 5002 --no-verify-ssl --deploy-hook /usr/local/sbin/handbook-deploy-acme

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/acme.handbook.test.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Renewing an existing certificate for acme.handbook.test

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all renewals succeeded:
  /etc/letsencrypt/live/acme.handbook.test/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The forced run ignores the not-yet-due expiry and goes through the same challenge, issuance, and hook a real renewal will take in production; the lab-only port and TLS options are the same ones labeled in Section 23.4.2. The renewal log lines end up in /var/log/letsencrypt/letsencrypt.log, and Python prints its InsecureRequestWarning lines to stderr during these test-server runs - a reminder, in this context accurate, that TLS verification was disabled for the local endpoint only.

After any renewal, confirm the served certificate rather than trusting the log: run sudo openssl s_client -connect 127.0.0.1:443 -servername acme.handbook.test </dev/null 2>/dev/null | openssl x509 -noout -serial -dates on the host and compare the serial and dates against certbot certificates; a changed serial means the reload really happened. Before relying on the timer, rehearse it against a public CA's staging environment with sudo certbot renew --dry-run, which performs the full challenge flow without writing to the live certificate paths. If you skip a hook, the equivalent discipline is manual: after any renewal, reload the server and check the served dates yourself.

23.4.4. Redirects, TLS Policy, and Certificate Troubleshooting

Everything this chapter has enabled adds up to a policy that is worth stating as one sentence: a name either serves HTTPS or it refuses to serve at all. The port 80 blocks exist to redirect (Apache's Redirect permanent, Nginx's return 301), every port 443 block sends HSTS, and the protocol floor is TLS 1.2.

Strict Transport Security is the header that makes the redirect durable: a browser that has seen Strict-Transport-Security: max-age=31536000 from a name will not attempt plain HTTP for that name for a year, closing the one window a downgrade attack had. Both servers set it with the always/error inclusion described in Section 23.4.1; Section 23.5.3 captures the header on a live proxied response.

The protocol floor is verifiable at the wire. The static site's ssl_protocols TLSv1.2 TLSv1.3 (and Apache's equivalent SSLProtocol line) refuse anything older, and the practice client can demonstrate both sides of that line. On client1, as john:

$ timeout 8 openssl s_client -connect app.handbook.test:443 -servername app.handbook.test -tls1_1 </dev/null
CONNECTED(00000003)
---
no peer certificate available
---
SSL handshake has read 0 bytes and written 7 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)

Selected output. Nothing was negotiated - the local OpenSSL 3.5 refuses to offer TLS 1.1 at all (no protocols available in the full output), and the server policy would refuse it anyway; the version is dead on both ends of the connection. TLS 1.2 proceeds, against the same edge listener:

$ timeout 8 openssl s_client -connect app.handbook.test:443 -servername app.handbook.test -tls1_2 </dev/null
CONNECTED(00000003)
---
Certificate chain
 0 s:CN=*.handbook.test, O=Handbook Lab
   i:CN=Handbook Lab Issuing CA, O=Handbook Lab
   a:PKEY: RSA, 2048 (bit); sigalg: sha256WithRSAEncryption
   v:NotBefore: Nov 22 17:02:18 2026 GMT; NotAfter: Feb 20 17:02:18 2027 GMT
 1 s:CN=Handbook Lab Issuing CA, O=Handbook Lab
   i:CN=Handbook Lab Root CA, O=Handbook Lab
   a:PKEY: RSA, 3072 (bit); sigalg: sha256WithRSAEncryption
   v:NotBefore: Nov 22 17:02:18 2026 GMT; NotAfter: Nov 21 17:02:18 2031 GMT
---
Server certificate
subject=CN=*.handbook.test, O=Handbook Lab
issuer=CN=Handbook Lab Issuing CA, O=Handbook Lab
---
New, TLSv1.2, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Protocol: TLSv1.2
Server public key is 2048 bit

Selected output; the leaf's PEM body and the session-detail lines are omitted. The full served chain is on display - leaf then intermediate, matching Figure 23.3 - and the negotiated cipher is a modern authenticated-encryption suite.

The remaining failures are the two every administrator meets first, and both have already been produced deliberately in this chapter:

  • Hostname mismatch. The certificate lists names; the request must use one of them. Asking by bare address fails, on client1, as john:
$ curl -sS --max-time 5 https://192.168.234.10/
curl: (60) SSL: no alternative certificate subject name matches target ipv4 address '192.168.234.10'
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection. To learn more about this situation
and how you can fix it, please visit the webpage mentioned above.

curl exits with status 60. The fix is on one side or the other: request by a name the certificate lists, or issue a certificate listing the address (SANs support IP: entries for that purpose).

  • Missing intermediate. The client reports unable to get local issuer certificate, as reproduced with openssl verify in Section 23.4.1. The server-side fix is to present leaf plus intermediate - the fullchain form every site in this chapter uses; the wire-side check is the two-certificate count from the same section.

When a client fails and neither cause fits, read the server's own record before guessing: Nginx logs handshake and upstream failures to the site's error_log and to the journal, Apache to the per-vhost ErrorLog, and curl -v on the client prints the negotiation step by step. Name-resolution mistakes announce themselves earlier - the getent hosts check from Section 23.1.3 resolves them in seconds.