To harden TLS on Nginx you disable the legacy protocols with ssl_protocols TLSv1.2 TLSv1.3;, replace the default cipher list with a vetted ssl_ciphers string that keeps only forward-secret ECDHE suites with AES-GCM or ChaCha20-Poly1305, and let TLS 1.3 negotiate its own fixed suites. Add OCSP stapling and a session cache, run nginx -t, reload, then confirm that a TLS 1.1 handshake is refused and the negotiated cipher is what you expect. The one thing that trips people up: ssl_ciphers controls TLS 1.2 and below only — TLS 1.3 suites are separate and are not set by that directive. This guide walks the exact directives, gives a current Mozilla intermediate cipher string, and shows how to prove the result instead of trusting it.
What you’ll accomplish
- Disable the deprecated TLS 1.0 and TLS 1.1 protocols so the server only speaks TLS 1.2 and TLS 1.3.
- Replace the cipher list with a vetted Mozilla intermediate string that keeps only forward-secret, authenticated-encryption suites.
- Confirm TLS 1.3 is offered and negotiating, and understand why its cipher suites live outside
ssl_ciphers. - Enable OCSP stapling and a shared session cache so the hardening does not cost you handshake latency.
- Verify the grade with
openssl s_client,nmap, ortestssl.shrather than assuming the config took effect.
Prerequisites
- Nginx built against OpenSSL 1.1.1 or newer — ideally OpenSSL 3.x — so that TLS 1.3 is available. Check with
nginx -V, which prints the OpenSSL version Nginx was compiled and is running against. - A working HTTPS site with a valid certificate and private key already configured. If you do not have one yet, set up the certificate first (see the related guide below).
- Access to the Nginx configuration and permission to run
nginx -tand reload the service. - An awareness that TLS 1.3 cipher suites are not controlled by
ssl_ciphers. They are a small fixed set negotiated by OpenSSL, and on newer OpenSSL you can influence them only withssl_conf_command Ciphersuites ..., not withssl_ciphers. - Honesty about the client-compatibility tradeoff. Disabling TLS 1.0/1.1 and RSA key-exchange suites locks out genuinely old clients — Android 4.x, Internet Explorer on Windows XP, some embedded devices and payment terminals. The Mozilla intermediate profile is the sane default for a general public site in 2026; only tighten to modern (TLS 1.3 only) if you know every client can reach it.
How it works
A TLS connection opens with a negotiation. The client sends a ClientHello that advertises the protocol versions it supports and an ordered list of cipher suites it is willing to use. The server compares that against its own configuration and picks one of each, then answers with a ServerHello naming the chosen protocol version and cipher suite. Everything after that is encrypted.
Your directives control which choices the server is allowed to make:
ssl_protocolsis the version filter. If the client offers TLS 1.0 but your directive lists onlyTLSv1.2 TLSv1.3, the server refuses the handshake rather than downgrading.ssl_ciphersis an OpenSSL cipher string that governs TLS 1.2 and below. It is where you strip out RSA key-exchange suites (no forward secrecy) and CBC-mode suites, leaving only ECDHE suites with AES-GCM or ChaCha20-Poly1305.- TLS 1.3 cipher suites are a separate, deliberately small set (
TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256). They are all forward-secret and modern by design, sossl_ciphersdoes not touch them. ssl_prefer_server_ciphersdecides whose ordering wins for TLS 1.2. Whenon, the server’s cipher order beats the client’s; whenoff, the client’s preference is honored. It has no effect on TLS 1.3, where the client always chooses.
Forward secrecy is the property that matters most here. ECDHE (Elliptic Curve Diffie-Hellman Ephemeral) key exchange derives a unique session key for every connection, so capturing the server’s private key later does not decrypt past recorded traffic. Every suite in the recommended list uses ECDHE for exactly this reason.
Step-by-step
-
Check the OpenSSL version Nginx is using. TLS 1.3 requires OpenSSL 1.1.1 or newer at both build and run time. Confirm it:
nginx -V 2>&1 | tr ' ' '\n' | grep -i opensslExpected output names a version at or above 1.1.1, for example
built with OpenSSL 3.0.13. If it reports 1.0.2 or older, TLS 1.3 is simply unavailable and no cipher directive can enable it — you need a newer Nginx/OpenSSL build first. -
Restrict the protocol versions. In your
serverblock or a shared TLS snippet, set:ssl_protocols TLSv1.2 TLSv1.3;This drops TLS 1.0 and TLS 1.1 entirely. On success,
nginx -tin a later step will pass and TLS 1.1 clients will be refused during validation. -
Set a vetted intermediate cipher list. Replace the default with the current Mozilla intermediate string, which keeps only ECDHE suites using AES-GCM or ChaCha20-Poly1305:
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:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305;There is no static RSA key exchange and no plain CBC suite in that list, so every negotiated TLS 1.2 session gets forward secrecy and AEAD encryption.
-
Let the client choose the TLS 1.2 order. The Mozilla intermediate profile recommends deferring to the client so that a client on battery can prefer ChaCha20:
ssl_prefer_server_ciphers off;Set this to
ononly if a compliance requirement forces a server-dictated order. It never affects TLS 1.3. -
Set the curve and session parameters. These keep the handshake efficient without weakening it:
ssl_ecdh_curve X25519:prime256v1:secp384r1; ssl_session_timeout 1d; ssl_session_cache shared:SSL:10m; ssl_session_tickets off;The shared cache lets resumed connections skip a full handshake;
10mholds roughly 40,000 sessions. -
Enable OCSP stapling. Stapling lets Nginx fetch and attach the certificate’s revocation status so the client does not have to contact the CA:
ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate /etc/nginx/ssl/chain.pem; resolver 1.1.1.1 8.8.8.8 valid=300s; resolver_timeout 5s;Stapling needs a working
resolverso Nginx can reach the OCSP responder named in the certificate. Thessl_trusted_certificateshould point at the CA chain used to verify the OCSP response. -
Test the configuration and reload. Never reload a live server without validating first:
nginx -tExpected output is
nginx: configuration file /etc/nginx/nginx.conf test is successful. Then apply it with a graceful reload that keeps existing connections alive:nginx -s reload -
Optional: drop to the modern profile. If every client can reach TLS 1.3, you can go further and serve TLS 1.3 only. Set
ssl_protocols TLSv1.3;and removessl_ciphers(it governs only TLS 1.2 and below, which you are no longer offering). Do this only when you have confirmed your entire audience supports TLS 1.3.
Validate it works
Prove the legacy protocols are actually refused. This handshake should fail:
openssl s_client -connect example.com:443 -tls1_1
Expected: the connection is rejected with an error such as no protocols available or sslv3 alert handshake failure, not a completed session. Repeat with -tls1 to confirm TLS 1.0 is also gone.
Confirm the negotiated protocol and cipher on a normal connection:
openssl s_client -connect example.com:443 </dev/null 2>/dev/null | grep -E "Protocol|Cipher"
Expected: a Protocol of TLSv1.3 (or TLSv1.2) and a Cipher that is one of your allowed ECDHE/AEAD suites — never an RSA-kx or CBC suite.
Get the full picture with a scanner. Either of these enumerates every accepted protocol and suite:
nmap --script ssl-enum-ciphers -p 443 example.com
testssl.sh example.com
Expected: TLS 1.0 and TLS 1.1 marked as not offered, TLS 1.2 showing only your allowed list, and TLS 1.3 present with its three fixed suites. testssl.sh also reports on OCSP stapling and forward secrecy, so it is the fastest way to confirm the whole change landed.
Troubleshooting
- TLS 1.3 is never offered. The most common cause is an old OpenSSL. Run
nginx -V— if it reports OpenSSL 1.0.2 or earlier, TLS 1.3 does not exist in that build and no cipher directive can conjure it. You need a package or build linked against OpenSSL 1.1.1 or newer. Adding TLS 1.3 suites tossl_ciphersdoes nothing here. ssl_ciphersseems to have no effect on the 1.3 suites. That is expected.ssl_ciphersgoverns TLS 1.2 and below only. To influence the TLS 1.3 suite set on newer OpenSSL you must usessl_conf_command Ciphersuites TLS_AES_256_GCM_SHA384:...;— but the default TLS 1.3 set is already sound, so most sites leave it alone.- Clients started failing after you disabled 1.0/1.1. Genuinely old clients — Android 4.x, IE on Windows XP, some payment terminals and IoT devices — cannot speak TLS 1.2. Check the failing user agents in your access logs before loosening anything. If a small legacy population truly must be served, that is usually a signal to put those clients behind a separate endpoint rather than weakening the main one.
- OCSP stapling is not working. Run
openssl s_client -connect example.com:443 -status </dev/null 2>/dev/null | grep -A2 "OCSP Response". If it shows no response, the usual causes are a missing or unreachableresolver, a certificate whose OCSP URI is empty, or a wrongssl_trusted_certificate. Nginx also staples lazily: the very first request after a reload may show no staple until Nginx has fetched one. - “no shared cipher” errors. You tightened the list past what the client can offer, or you kept
ssl_prefer_server_ciphers onwith a list the client and server cannot agree on. Widen back to the full Mozilla intermediate string and retest — if a specific client still fails, capture its ClientHello withtestssl.shto see which suites it actually proposes.
When this is the wrong approach
If TLS is terminated somewhere other than this Nginx — a CDN, a cloud load balancer, or a reverse proxy in front — then hardening these directives changes nothing the public sees. The termination point owns the cipher negotiation, so harden there instead (the CDN’s TLS profile, the load balancer’s security policy) and treat the origin Nginx as an internal hop. Likewise, if you are contractually required to support ancient clients, or a compliance profile mandates a specific and different suite list, follow that mandate rather than the Mozilla defaults — but document the exception and the clients it protects.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.
Related guides
- Nginx security headers — HSTS, CSP, and the rest of the response-header layer that sits on top of a hardened TLS stack.
- Let’s Encrypt SSL on Nginx — get the certificate in place before you tune the cipher suites.
- Mozilla SSL Configuration Generator — the source of the intermediate and modern profiles, regenerated as recommendations change.
- Nginx ngx_http_ssl_module reference — the authoritative directive documentation.