nginx answers a client certificate with 400 The SSL certificate error
Fix it fast
Most common cause, 1 of 4The chain has more intermediate CAs than ssl_verify_depth permits
Set the depth to the number of intermediates the chain really has, and keep those intermediates with the root in the CA file.
ssl_client_certificate /etc/nginx/client-ca.pem;
ssl_verify_client on;
ssl_verify_depth 2;Short answer
400 The SSL certificate error is nginx's internal code 495: OpenSSL refused the client certificate during verification. The page hides the reason, so log $ssl_client_verify and set error_log to info. Then fix what the number says: a chain deeper than ssl_verify_depth, a missing CA, expired dates or a stale CRL. Covers nginx 1.30 and 1.31.
Which cause do you have?
Make nginx tell you the reason. $ssl_client_verify holds SUCCESS, FAILED:reason or NONE, and the matching error log line is written at info level, which the default error level hides. Add both, reload, repeat the request and read the number in brackets.
# http block
log_format mtls '$remote_addr $ssl_client_verify "$ssl_client_s_dn" "$ssl_client_i_dn"';
access_log /var/log/nginx/mtls.log mtls;
error_log /var/log/nginx/error.log info;
sudo nginx -t && sudo systemctl reload nginx
sudo grep "client SSL certificate verify error" /var/log/nginx/error.log | tail -n 3Then find the line you see in this list and open its fix:
- 1The chain has more intermediate CAs than ssl_verify_depth permits
client SSL certificate verify error: (22:certificate chain too long) - 2The CA file nginx loads lacks the client certificate's issuer
client SSL certificate verify error: (20:unable to get local issuer certificate) - 3The certificate is outside its validity dates, or the server clock is off
client SSL certificate verify error: (10:certificate has expired) or (9:certificate is not yet valid) - 4The CRL file is out of date, incomplete or revokes the certificate
client SSL certificate verify error: (12:CRL has expired), (3:unable to get certificate CRL) or (23:certificate revoked), with ssl_crl configured
What does the error look like?
400 Bad Request400 The SSL certificate errorclient SSL certificate verify error: (20:unable to get local issuer certificate)client SSL certificate verify error: (22:certificate chain too long)
Cause 1 of 4
The chain has more intermediate CAs than ssl_verify_depth permits
You seeclient SSL certificate verify error: (22:certificate chain too long)
Check
Error 22 behind the 400 page means the client chain holds more intermediate CAs than ssl_verify_depth allows. The directive defaults to 1, and OpenSSL's verify depth counts only intermediates, not the client certificate or the trust anchor, so a certificate two intermediates below the root breaks the default. List the issuers to count them.
openssl x509 -in client.crt -noout -subject -issuer
grep -c "BEGIN CERTIFICATE" /etc/nginx/client-ca.pemFix
Set the depth to the number of intermediates the chain really has, and keep those intermediates with the root in the CA file.
ssl_client_certificate /etc/nginx/client-ca.pem;
ssl_verify_client on;
ssl_verify_depth 2;Verify
After a reload, the next request logs SUCCESS in mtls.log.
sudo nginx -t && sudo systemctl reload nginx
tail -n 3 /var/log/nginx/mtls.logConfirmed by docs.openssl.org
Cause 2 of 4
The CA file nginx loads lacks the client certificate's issuer
You seeclient SSL certificate verify error: (20:unable to get local issuer certificate)
Check
Error 20 behind the 400 page means nginx's trusted CA file does not contain the CA that issued the client certificate. Client certificates are checked against the PEM file in ssl_client_certificate or ssl_trusted_certificate, so a missing intermediate or root there leaves the issuer unknown. Run the same check from the shell against the same file.
openssl verify -CAfile /etc/nginx/client-ca.pem client.crtFix
Add the missing CA certificates in PEM form. If you would rather not send the CA names to every client during the handshake, load them with ssl_trusted_certificate: nginx sends the list from ssl_client_certificate but not that one.
cat intermediate.pem root.pem >> /etc/nginx/client-ca.pem
# nginx
ssl_trusted_certificate /etc/nginx/client-ca.pem;
ssl_verify_client on;Verify
openssl verify ends with OK, and the reloaded nginx logs SUCCESS.
openssl verify -CAfile /etc/nginx/client-ca.pem client.crt
sudo nginx -t && sudo systemctl reload nginxConfirmed by nginx.org
Cause 3 of 4
The certificate is outside its validity dates, or the server clock is off
You seeclient SSL certificate verify error: (10:certificate has expired) or (9:certificate is not yet valid)
Check
Errors 10 and 9 behind the 400 page mean the client certificate's validity dates do not include the nginx host's current time. OpenSSL refuses a certificate whose notAfter has passed or whose notBefore is still ahead, so print both dates next to the host clock.
openssl x509 -in client.crt -noout -dates
date -uFix
An expired certificate has to be reissued by its CA. If the dates are fine and the clock is wrong, turn network time synchronisation on.
timedatectl status
sudo timedatectl set-ntp trueVerify
-checkend 0 reports that the certificate will not expire, and the request reaches the app.
openssl x509 -in client.crt -noout -checkend 0Confirmed by raw.githubusercontent.com
Cause 4 of 4
The CRL file is out of date, incomplete or revokes the certificate
You seeclient SSL certificate verify error: (12:CRL has expired), (3:unable to get certificate CRL) or (23:certificate revoked), with ssl_crl configured
Check
Errors 12, 3 and 23 behind the 400 page come from the revocation list in ssl_crl. nginx reads every CRL from that one PEM file, and with intermediate CAs their lists belong there too, so a list past its nextUpdate date, or a missing list for one intermediate, rejects every certificate below it.
grep -R -n "ssl_crl" /etc/nginx/
openssl crl -in /etc/nginx/client.crl -noout -lastupdate -nextupdateFix
Have each CA publish a fresh CRL and combine the root's and every intermediate's list into the one file. A certificate that is listed as revoked needs a replacement, not a config change.
cat root.crl.pem intermediate.crl.pem > /etc/nginx/client.crl
ssl_crl /etc/nginx/client.crl;Verify
nextUpdate shows a future date, and requests pass after a reload.
openssl crl -in /etc/nginx/client.crl -noout -nextupdate
sudo nginx -t && sudo systemctl reload nginxConfirmed by nginx.org
How do I stop it coming back?
- Put the CRL's nextUpdate date in your monitoring; a lapsed CRL locks out every client at once.
- Run openssl verify against the exact CA file nginx loads before giving out a new client certificate.
- Keep $ssl_client_verify and the certificate subject in the access log on every site that uses client certificates.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, stegnor.com.