Certificate chain in the wrong order: PEM bundle must start with the leaf, then intermediates
Servers or clients choke because the certificates in the file are in the wrong order or the root was included first.
certificate chain wrong ordernginx ssl_certificate chain in wrong orderSSL_CTX_use_certificate_chain_file wrong orderkey values mismatch chain order leaf firstPEM bundle order intermediate first Meaning
The bundle must be leaf → intermediate(s) (optionally no root). Some stacks (nginx, older OpenSSL) won't recover from wrong ordering. Rebuild the file: cat server.crt intermediate.crt > fullchain.pem and verify with openssl crl2pkcs7 -nocrl -certfile fullchain.pem | openssl pkcs7 -print_certs -noout.
Common causes
- Intermediate placed before the leaf
- Root first in the bundle
- Wrong order from concatenating downloads
- Missing intermediate
- Duplicate certificates
⚡ Quick fix
- Order: leaf, intermediates, (root optional)
- Rebuild with
cat - Verify with
openssl verify -untrusted
Detailed fix by platform
Shell
- bash
cat server.crt intermediate.crt > fullchain.pem openssl verify -CAfile root.pem -untrusted intermediate.crt server.crt
How to diagnose
- First cert — Leaf?
- Order — Correct?
- Missing — Intermediate?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in SSL / TLS
- HTTPSConnectionPool: Max retries exceeded (SSLError) Python requests: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: /v1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] ...')))
- DST Root CA X3 expired (old clients fail) Old clients: certificate has expired — Let's Encrypt chain uses expired DST Root CA X3 (OpenSSL 1.0.x, Android < 7.1.1)
- Keystore was tampered with, or password was incorrect Java keytool: java.io.IOException: Keystore was tampered with, or password was incorrect
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026