TLS Tuning: Protocols, Sessions & Stapling
Terminating TLS in Nginx & Caddy got HTTPS working with a private CA and checked it with openssl s_client. This lesson tunes it: which protocol versions and ciphers to allow, serving RSA and ECDSA certificates side by side, making repeat handshakes cheap with session resumption, and what became of OCSP stapling. Every session creates its own CA, because the sandbox has no public certificates.
Protocols and ciphers
| Setting | Nginx 1.24 default | Recommended ("intermediate" profile) |
|---|---|---|
ssl_protocols |
TLSv1 TLSv1.1 TLSv1.2 TLSv1.3 (1.23.4 added 1.3 to the default; 1.27.3 dropped 1.0 and 1.1) |
TLSv1.2 TLSv1.3 |
ssl_ciphers (TLS 1.2 only) |
HIGH:!aNULL:!MD5 |
ECDHE with AES-GCM or ChaCha20 only |
ssl_prefer_server_ciphers |
off |
off (all remaining ciphers are strong; let clients pick the fastest for their hardware) |
| TLS 1.3 suites | OpenSSL's defaults | leave them; change with ssl_conf_command Ciphersuites … (since 1.19.4) |
In fact, Ubuntu's own /etc/nginx/nginx.conf still lists ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;; OpenSSL 3's default security level then refuses TLS 1.0/1.1 anyway, but say what you mean explicitly. The default cipher string, though, still allows old CBC-mode suites with SHA-1 MACs for TLS 1.2, as the session shows:
openssl req -x509 -new -noenc -newkey ec -pkeyopt ec_paramgen_curve:P-256 -keyout ca.key -out ca.crt -days 365 -subj "/CN=TAD Lab Root CA" 2>/dev/null
openssl req -new -noenc -newkey ec -pkeyopt ec_paramgen_curve:P-256 -keyout app.key -out app.csr -subj "/CN=app.example.test" 2>/dev/null
openssl x509 -req -in app.csr -CA ca.crt -CAkey ca.key -set_serial 1 -days 90 -out app.crt -extfile <(printf 'subjectAltName=DNS:app.example.test\n') 2>/dev/null
conf() { cat > nginx.conf <<EOF
pid nginx.pid;
error_log error.log;
events {}
http {
access_log off;
ssl_protocols TLSv1.2 TLSv1.3;
$1
server { listen 127.0.0.1:8443 ssl; ssl_certificate app.crt; ssl_certificate_key app.key; return 200 "ok\n"; }
}
EOF
}
try() { openssl s_client -connect 127.0.0.1:8443 -tls1_2 -cipher "$1" -brief < /dev/null 2>&1 | grep -q '^Ciphersuite' && echo "accepted $1" || echo "refused $1"; }
conf ""
nginx -p "$PWD" -c nginx.conf -e stderr
echo "--- default ssl_ciphers:"
try ECDHE-ECDSA-AES128-GCM-SHA256; try ECDHE-ECDSA-AES128-SHA
conf "ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;"
nginx -p "$PWD" -c nginx.conf -e stderr -s reload 2>/dev/null; sleep 0.5
echo "--- intermediate profile:"
try ECDHE-ECDSA-AES128-GCM-SHA256; try ECDHE-ECDSA-AES128-SHA
nginx -p "$PWD" -c nginx.conf -e stderr -s quit 2>/dev/null--- default ssl_ciphers:
accepted ECDHE-ECDSA-AES128-GCM-SHA256
accepted ECDHE-ECDSA-AES128-SHA
--- intermediate profile:
accepted ECDHE-ECDSA-AES128-GCM-SHA256
refused ECDHE-ECDSA-AES128-SHA
The cipher list is the TLS 1.2 part of Mozilla's "intermediate" profile (ssl-config.mozilla.org generates complete server configs for each server and version; use it rather than copying lists from old blog posts). TLS 1.3 has only five suites, all strong, so there is nothing to remove there.
RSA and ECDSA side by side
ECDSA certificates (P-256 keys) make handshakes cheaper and smaller than RSA-2048. A few old clients only understand RSA, so Nginx can hold both, and picks per connection from what the client says it supports:
openssl req -x509 -new -noenc -newkey ec -pkeyopt ec_paramgen_curve:P-256 -keyout ca.key -out ca.crt -days 365 -subj "/CN=TAD Lab Root CA" 2>/dev/null
for t in ec rsa; do
if [ $t = ec ]; then key="-newkey ec -pkeyopt ec_paramgen_curve:P-256"; else key="-newkey rsa:2048"; fi
openssl req -new -noenc $key -keyout app-$t.key -out app-$t.csr -subj "/CN=app.example.test" 2>/dev/null
openssl x509 -req -in app-$t.csr -CA ca.crt -CAkey ca.key -set_serial 1 -days 90 -out app-$t.crt -extfile <(printf 'subjectAltName=DNS:app.example.test\n') 2>/dev/null
done
cat > nginx.conf <<'EOF'
pid nginx.pid;
error_log stderr;
events {}
http {
access_log off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache shared:SSL:10m; # about 40,000 sessions
ssl_session_timeout 1h;
ssl_session_tickets off;
server {
listen 127.0.0.1:8443 ssl;
server_name app.example.test;
ssl_certificate app-ec.crt; ssl_certificate_key app-ec.key;
ssl_certificate app-rsa.crt; ssl_certificate_key app-rsa.key;
return 200 "ok\n";
}
}
EOF
nginx -p "$PWD" -c nginx.conf -e stderr
S="openssl s_client -connect 127.0.0.1:8443 -servername app.example.test -CAfile ca.crt"
echo "--- a modern client:"
$S -brief < /dev/null 2>&1 | grep -E 'Protocol|Ciphersuite|Verification|Temp Key'
$S < /dev/null 2>&1 | grep 'Server public key'
echo "--- a client that only accepts RSA signatures:"
$S -tls1_2 -sigalgs 'RSA+SHA256:RSA-PSS+SHA256' -brief < /dev/null 2>&1 | grep -E 'Protocol|Ciphersuite'
$S -tls1_2 -sigalgs 'RSA+SHA256:RSA-PSS+SHA256' < /dev/null 2>&1 | grep 'Server public key'
echo "--- session resumption (TLS 1.2, server-side cache):"
$S -tls1_2 -sess_out sess.pem < /dev/null 2>&1 | grep -E '^(New|Reused),'
$S -tls1_2 -sess_in sess.pem < /dev/null 2>&1 | grep -E '^(New|Reused),'
nginx -p "$PWD" -c nginx.conf -e stderr -s quit 2>/dev/null--- a modern client:
Protocol version: TLSv1.3
Ciphersuite: TLS_AES_256_GCM_SHA384
Verification: OK
Server Temp Key: X25519, 253 bits
Server public key is 256 bit
--- a client that only accepts RSA signatures:
Protocol version: TLSv1.2
Ciphersuite: ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
--- session resumption (TLS 1.2, server-side cache):
New, TLSv1.2, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384
Reused, TLSv1.2, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384
The default client got the ECDSA certificate (a 256-bit P-256 key) with an X25519 key exchange; the RSA-only client got the 2048-bit RSA certificate from the same server block. Renew both certificates together: monitoring that only checks one of them (Renewal & Expiry Monitoring) misses the other expiring.
Session resumption
A full handshake costs asymmetric crypto on the server and, before TLS 1.3, an extra round trip. Resumption lets a returning client skip most of it. The second connection above reported Reused: the client presented the session it saved, and the server found it in its cache. Two mechanisms:
Session cache (ssl_session_cache shared:SSL:10m) |
Session tickets (ssl_session_tickets on, the default) |
|
|---|---|---|
| State lives | on the server, in shared memory for all workers | in the client, encrypted with a server key |
| Several servers | each has its own cache: resumption only works on the same server | works across servers only if they share the ticket key (ssl_session_ticket_key) |
| Risk | memory | the ticket key decrypts every session that used it: a key that never rotates weakens forward secrecy |
Nginx generates a random ticket key at start and keeps it until restart, and each server behind a balancer has a different one. The common advice is: use the shared cache, and either turn tickets off or rotate a shared key file regularly (and reload). TLS 1.3 always resumes with tickets (PSK); with ssl_session_tickets off, Nginx doesn't issue them.
OCSP stapling, then and now
OCSP lets a client ask the CA whether a certificate was revoked; stapling (ssl_stapling on; ssl_stapling_verify on;) has the server fetch that answer and send it inside the handshake, so clients don't contact the CA. It needs a certificate with an OCSP URL and a resolver directive for the CA's host.
Let's Encrypt ended its OCSP service in 2025 (certificates no longer carry an OCSP URL) in favour of certificate revocation lists, and browsers mostly rely on their own revocation lists anyway. For Let's Encrypt certificates, stapling directives now do nothing except log a warning that the certificate has no OCSP responder URL. Keep them only for CAs that still run OCSP, and check your CA's current status.
# Sample: only meaningful with a CA that still provides OCSP
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/ssl/certs/ca-chain.pem; # to verify the OCSP response
resolver 127.0.0.53 valid=300s;Other settings worth knowing
| Directive | Note |
|---|---|
ssl_ecdh_curve X25519:prime256v1; |
key-exchange groups; the defaults are fine. Hybrid post-quantum groups (X25519MLKEM768) need OpenSSL 3.5+, which Ubuntu 24.04's OpenSSL 3.0 doesn't have |
ssl_dhparam |
only for the old DHE ciphers; not needed with an ECDHE-only list |
ssl_early_data on; |
TLS 1.3 0-RTT: faster, but early data can be replayed; pass $ssl_early_data to the app and allow it only for idempotent requests |
ssl_buffer_size 4k; |
smaller TLS records get the first bytes to the browser sooner (time to first byte), at some throughput cost |
Test yourself
Nginx 1.24 with ssl_protocols TLSv1.2 TLSv1.3; and no ssl_ciphers. What did the session show?
- Only AEAD ciphers are accepted
- Old CBC-mode ciphers with SHA-1 are still accepted for TLS 1.2 until you set
ssl_ciphers - TLS 1.2 is refused
- Only RSA works
A server block lists both an ECDSA and an RSA certificate. Which does a client get?
- Always the first one
- The one matching the signature algorithms the client supports; modern clients get ECDSA
- Both
- A random one
Why can session tickets weaken forward secrecy?
- They use RSA
- Every session encrypted under a ticket key can be decrypted by whoever obtains that key, so a key that is never rotated is a long-lived secret
- They disable ECDHE
- They are sent in plain text