Configure mTLS for APIs: Client Certificates
To configure mTLS for APIs you need three things: a private CA, a client certificate issued from it, and a proxy that refuses connections without one. Normal HTTPS authenticates only the server. With mutual TLS (mTLS) the client also presents a certificate, and the server checks it against a CA it trusts.
mTLS for APIs: use a private CA
Client certificates are normally signed by a CA you control, not a public one. Public CA certificates are issued for proving server identity, and client authentication is not the job they are built for. If you plan to use a public CA for client certificates, check that CA's current policy first. A private CA also lets you choose lifetimes and revoke by removing trust. Treat the CA key as your most sensitive file, and read how to protect SSL private keys.
Step 1: Create the CA
openssl genrsa -out ca.key 4096
openssl req -x509 -new -key ca.key -sha256 -days 1825 \
-subj "/CN=Example Internal API CA" -out ca.pemStep 2: Issue a client certificate
openssl genrsa -out client1.key 2048
openssl req -new -key client1.key \
-subj "/CN=client1" -out client1.csr
printf 'extendedKeyUsage=clientAuth\n' > ext.cnf
openssl x509 -req -in client1.csr -CA ca.pem -CAkey ca.key \
-CAcreateserial -days 90 -sha256 -extfile ext.cnf \
-out client1.pemThe clientAuth extended key usage states what the certificate is for. A short lifetime, such as 90 days or less, limits the damage from a stolen key, as long as you automate reissuing. The commands for generating keys and requests are explained further in generating a private key and CSR.
Step 3: Enforce client certificates in Nginx
server {
listen 443 ssl;
server_name api.example.com;
ssl_certificate /etc/ssl/api/fullchain.pem;
ssl_certificate_key /etc/ssl/api/privkey.pem;
ssl_client_certificate /etc/ssl/api/ca.pem;
ssl_verify_client on;
ssl_verify_depth 2;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Client-DN $ssl_client_s_dn;
proxy_set_header X-Client-Verify $ssl_client_verify;
}
}The server certificate is still a normal public one; ssl_client_certificate names the private CA used only to verify clients. With ssl_verify_client on the handshake fails for clients without a valid certificate. Use optional if only some paths need it, and then check $ssl_client_verify in the config. Pass identity to the backend only from this proxy, and make sure the backend rejects the same headers when they come from anywhere else.
Step 4: Test with curl
curl https://api.example.com/ \
--cert client1.pem --key client1.key
curl -i https://api.example.com/The first call should succeed. The second, without a certificate, should fail at the handshake or return a 400 range error, depending on the server. If the first fails, run openssl s_client -connect api.example.com:443 -cert client1.pem -key client1.key and read the alert; our OpenSSL testing guide explains the messages.
mTLS for APIs: common failures
| Symptom | Likely cause |
|---|---|
| Handshake failure with no certificate sent | Client does not send a cert, or its issuer is not in the server's accepted list |
| Certificate verify failed | Wrong CA file or expired client certificate |
| Unsupported certificate purpose | Missing clientAuth key usage |
| Works with curl, fails in the app | The app's TLS library has no key and cert configured |
Rotation and revocation
Plan rotation before launch. Issue overlapping certificates so clients can switch without downtime, and track expiry dates in an inventory. For revocation, Nginx supports a CRL via ssl_crl, or you can simply stop trusting a compromised client by issuing a new CA generation for the group. In Kubernetes and service mesh setups, much of this is automated; see Configure SSL in Kubernetes. For database and broker equivalents of the same pattern, see Configure SSL for MySQL.
Where else mTLS fits
Gateways and service meshes can enforce it for you; see How to Secure an API Gateway with TLS for the termination choices. Keep the number of CAs small, give each client its own certificate rather than sharing one, and log the certificate subject on every request so you can trace activity to a client.
Related reading: generating a private key and CSR, securing an API gateway with TLS and SSL for Node.js.
Frequently Asked Questions
Do I need a public CA for mTLS client certificates?
No, and it is usually the wrong tool. A private CA you control is the normal choice for client certificates, because you decide who gets one and you can revoke it.
How long should a client certificate last?
As short as your rotation can handle. A short lifetime limits the damage from a stolen key, but only if reissuing is automated.
What happens when a client certificate is revoked?
The server checks the certificate against your CA and, if you use a revocation list or OCSP for your own CA, refuses it. Otherwise you revoke by removing trust in that certificate's issuer.
✅ Post-Installation Verification & SEO Checklist
After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:
- Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
- Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
- Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
- Confirm both root and
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.