A busy Nginx frontend doing 3000 fresh TLS handshakes per second was pegging a core on RSA private-key operations, even with an EC certificate and modern OpenSSL. The fix wasn’t a faster CPU — it was enabling shared TLS session resume so the 60% of clients that reconnect within an hour skip the handshake entirely. This article walks through ssl_session_cache, ssl_session_tickets, and the multi-worker pitfalls that make the defaults wrong on any production frontend.
How to verify
Check whether resume is happening at all before tuning anything:
# Inspect a real handshake to see if resume succeeded
echo | openssl s_client -connect example.com:443 -reconnect 2>&1 \
| grep -E 'Reused|New|Session-ID|Session-Ticket'
# Count fresh vs resumed handshakes from access logs (custom log format required)
awk '{print $ssl_session_reused}' /var/log/nginx/access.log \
| sort | uniq -c
# Per-worker session-cache stats via stub_status equivalent: requires nginx-vts module
curl -s http://127.0.0.1:8080/status/format/json | jq '.sslHandshakes'
# Check the Nginx config and reload-time complaints
nginx -T 2>&1 | grep -E 'ssl_session_(cache|tickets|timeout)'
Reused, TLSv1.3 on the s_client output means the resume path is working. New, TLSv1.3 on every reconnect attempt means the session isn’t being cached — either the cache is the default per-worker built-in (which doesn’t share across workers), or tickets are off, or the timeout is shorter than the gap.
What’s happening
A fresh TLS handshake costs a couple of asymmetric crypto operations, two round-trips, and on RSA certs a fairly expensive private-key signature. Modern hardware does thousands per second, but at scale that’s millions of joules and a sizeable share of your CPU budget. TLS resume — Session ID cache or Session Tickets — lets a returning client and the server skip all of that and reuse the existing master secret.
Two flavors:
- Session ID cache. The server keeps a server-side cache keyed by session ID; the client presents the ID on reconnect and the server looks it up. Stateful — the server must remember every session. Nginx implements this as a shared memory zone or a per-worker built-in.
- Session Tickets. The server encrypts the session state with a key it owns, hands the ciphertext (the ticket) to the client, and on reconnect the client presents the ticket. Stateless — the server just needs the ticket key. Works across a fleet if all servers share the ticket key.
The ssl_session_cache directive has three meaningful modes:
off— disable Session ID cache entirely (rare; you’d only do this if every client uses tickets).none— the cache appears to work to the client but no resumption ever happens (used in tests).shared:NAME:SIZE— a shared memory zone accessible to all worker processes. This is the one you want on multi-worker Nginx. Without it, each worker has its own built-in cache and a client that lands on worker 3 then worker 7 seesNewboth times.
The default is a per-worker built-in cache of 256 entries. On 8 workers that’s 256 islands. A real frontend wants shared:SSL:50m (about 200k sessions) or larger.
TLS 1.3 changes the picture: Session IDs are gone in 1.3, but 0-RTT and the new ticket-based resume still flow through the same shared cache and ticket-key plumbing. Tuning the cache is still meaningful.
The procedure
-
Replace the default cache with a shared zone. In the
http {}block (so all servers share it):ssl_session_cache shared:SSL:50m; ssl_session_timeout 1h; ssl_session_tickets on;50mof shared memory holds roughly 200,000 sessions (about 4 KB per session). Size for your peak concurrent client count over the timeout window.1htimeout matches typical client behavior — long enough to capture page-to-page reuse, short enough that a compromised session has bounded value. -
Pin the ticket key across the fleet. If you have multiple Nginx instances (HA pair, autoscaled fleet, multiple regions terminating the same cert), every instance must have the same ticket key, or a client landing on instance B with a ticket from instance A will fall back to a full handshake:
# Generate once, distribute via your config-management channel openssl rand 80 > /etc/nginx/ssl/ticket.key chmod 600 /etc/nginx/ssl/ticket.keyssl_session_ticket_key /etc/nginx/ssl/ticket.key;Without
ssl_session_ticket_key, Nginx generates a fresh random key on each worker start — works on a single host, useless across a fleet, lost on reload. -
Rotate the ticket key on a schedule. A stolen ticket key lets an attacker decrypt past TLS sessions that used it (forward secrecy is undermined). Rotate at least daily on internet-facing frontends. Nginx supports multiple keys — the first is used to encrypt new tickets, the rest are used to decrypt presented tickets:
ssl_session_ticket_key /etc/nginx/ssl/ticket-current.key; ssl_session_ticket_key /etc/nginx/ssl/ticket-previous.key;A rotation cron generates a new current key, promotes the old current to previous, deletes the older-previous, then reloads Nginx (
nginx -s reload). Existing client tickets from yesterday still decrypt; new tickets use today’s key. -
Force the session cache to be honored on TLS 1.3. TLS 1.3 doesn’t carry a Session ID, so resume only happens via tickets. If you’ve disabled tickets globally (some compliance audits ask for this), TLS 1.3 clients will always full-handshake. Re-enable tickets, or accept the cost:
ssl_session_tickets on; ssl_protocols TLSv1.2 TLSv1.3; -
Measure the resume rate. Add
$ssl_session_reusedto your log format and watch the hit ratio. Healthy frontends with returning clients see 50-80% resume rates; static-asset edges see 90%+:log_format ssl_main '$remote_addr - $ssl_session_reused $ssl_protocol ' '$ssl_cipher $request_time';Plot the ratio on a dashboard. A drop usually means a deploy reset the cache (workers restarted), a ticket-key rotation went wrong, or a new client cohort doesn’t honor tickets.
Operational notes
nginx -s reloadpreserves the shared cache (workers are replaced, the shared memory zone stays). A fullsystemctl restart nginxwipes it — schedule restarts off-peak.- The default
ssl_session_timeoutis 5 minutes. That’s far too short for resumption to matter — make it at least 1 hour. - TLS 1.3 0-RTT (early data) is off by default. Enable with
ssl_early_data on;only if your application is idempotent for replays — POST endpoints are not safe candidates. - If you front the cert with a CDN or AWS ALB, resume is the LB’s problem, not Nginx’s. Tuning Nginx’s session cache for traffic that’s already resumed at the edge is fixing the wrong layer.
shared:SSL:50mis shared across allserverblocks. Per-tenant isolation requires a per-servershared:TENANT:10mzone, which most frontends don’t bother with.
Stack Harbor runs Nginx frontends with shared session caches, rotated ticket keys, and resume monitoring built into the dashboards we hand customers. If you’re seeing CPU pegged on handshake math and have ruled out unhealthy clients, this is the kind of tuning we do as part of managed operations.