Nginx Mutual TLS and Certificate Rotation
What mutual TLS changes
In ordinary server-authenticated TLS, the client validates the server. Mutual TLS adds certificate-based client authentication: the server requests a certificate and the client proves possession of its corresponding private key. Use separate trust roots for server and client certificates when the deployment calls for separate trust domains. The client must still validate the server.
listen 127.0.0.1:9443 ssl;server_name edge.test;ssl_certificate certs/edge.crt;ssl_certificate_key certs/edge.key;ssl_client_certificate certs/client-ca.crt;ssl_verify_client on;ssl_verify_depth 1;The client CA bundle determines which client certificate chains are accepted. With on, a valid certificate is required; optional allows absence but verifies a supplied certificate. optional_no_ca deliberately delegates trust validation elsewhere and must not be used as an authentication shortcut. Nginx exposes the verification outcome through $ssl_client_verify. Missing and invalid certificate cases can produce internal 496 and 495 codes respectively, which may be mapped to ordinary HTTP errors; do not assume clients always see those numbers.
Authentication is not authorization
A certificate signed by a trusted CA may identify many different clients. A valid chain does not grant administrator permissions. Define a stable identity mapping, such as a managed certificate identifier linked to an application principal, then enforce resource authorization separately. In this fixture all certificates from the synthetic client CA may read one non-sensitive marker; this is intentionally a small closed trust domain, not an enterprise identity policy.
curl --noproxy "*" --cacert certs/server-ca.crt \ --cert certs/client.crt --key certs/client.key \ --resolve edge.test:9443:127.0.0.1 https://edge.test:9443/Expected response: origin-ok. Without a client certificate or with a certificate from the wrong CA, access must fail. If forwarding identity metadata to an application, overwrite client-supplied headers at the trusted edge and prevent direct access to the application. Do not use arbitrary subject text alone as a trusted identity or log full certificates without a justified policy.
Client certificates for the upstream leg
proxy_ssl_certificate certs/proxy-client.crt;proxy_ssl_certificate_key certs/proxy-client.key;proxy_ssl_verify on;These settings present a separate Nginx workload certificate to the backend. They do not forward the browser private key or automatically impersonate the browser. The backend needs a matching client trust policy. Keep keys scoped and protect file permissions. This optional extension is documentation-only; the supplied backend fixture requires server authentication, not upstream client authentication.
Rotate trust without losing access
1. Add new approved CA while old CA remains trusted.2. Issue and test new client credentials.3. Migrate clients; observe success and failures.4. Remove old CA after approved overlap.5. Test old credentials fail and new credentials work.For ordinary rotation, overlap can prevent downtime, but do not retain a compromised CA simply for convenience. Treat revocation, established sessions, resumption and cached authorization separately. Validate both negative and positive cases, keep a reviewed rollback plan, and reload only a known lab-owned instance after testing. A successful reload alone is not evidence that old trust is gone.
Practice
Build an access matrix for no certificate, trusted client, untrusted client and server-only certificate presented as a client. Explain why successful authentication still requires application authorization. Sources: https://nginx.org/en/docs/http/ngx_http_ssl_module.html; https://nginx.org/en/docs/http/ngx_http_proxy_module.html; https://docs.openssl.org/3.5/man1/openssl-verification-options/.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx Mutual TLS and Certificate Rotation
Require client certificates, separate authentication from authorization, and plan trust rotation across a service boundary.
What does ssl_verify_client on require?
What is the meaning of optional_no_ca?
Does a trusted client certificate imply administrator access?
Which credential can Nginx present to an mTLS backend?
What must a trust rotation test after removing the old CA?