chain order SSL / TLS Origin: Network OSI layer 6 · Presentation Last updated 18 Nov 2026

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.

Exact message you may see 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
Seen on: SSL Nginx OpenSSL

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

  1. Order: leaf, intermediates, (root optional)
  2. Rebuild with cat
  3. Verify with openssl verify -untrusted

Detailed fix by platform

Shell

  1. bash
    cat server.crt intermediate.crt > fullchain.pem
    openssl verify -CAfile root.pem -untrusted intermediate.crt server.crt

How to diagnose

  1. First cert — Leaf?
  2. Order — Correct?
  3. 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:

Where this error sits

Origin: Network. Errors that are often confused with or caused by this one (click to open):

bad end line — PEM routines: bad end line / no start line — Windows CRLF line endings or truncated PEM file (SSL / TLS)bad end lineDjango — Django send_mail: ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] (EMAIL_USE_SSL vs EMAIL_USE_TLS on the wrong port) (Email / SMTP)Djangoerror 24 — openssl verify error:num=24:invalid CA certificate (SSL / TLS)error 24HAProxy — HAProxy: unable to load SSL private key from PEM file / no certificate found (crt bundle format) (SSL / TLS)HAProxyincomplete certificate chain — SSL Labs: Chain issues: Incomplete — Extra download (intermediate certificate missing) (SSL / TLS)incomplete certificat…intermediate expired — Certificate chain error: an expired intermediate/cross-signed certificate is still served (leaf is valid) (SSL / TLS)intermediate expiredtrust anchor — Android: SSLHandshakeException: Trust anchor for certification path not found (SSL / TLS)trust anchorunable to get local issuer certificate — OpenSSL: error:num=20:unable to get local issuer certificate / SSL: CERTIFICATE_VERIFY_FAILED (SSL / TLS)unable to get local i…chain ord…

Explore the map of this error Full error map →

🧠 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.