SSL certificate problems: how to diagnose and fix the common ones
In this article10 sections
A browser warning on your own website is one of the fastest ways to lose a visitor. “Your connection is not private”, a padlock with a red line through it, an API client that suddenly refuses to connect: all of them come from a small number of causes, and each leaves a different fingerprint.
The mistake most people make is to reissue the certificate straight away. Sometimes that is right. Often the certificate is fine and something around it is wrong: the file served, the chain, the name, a proxy in front of the server, a renewal job that quietly stopped months ago. This guide shows how to read the evidence first, with two commands, and then fix the right thing.
Start with what the server actually sends
Do not trust what you think is installed. Ask the server, from outside if you can:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
This prints, for the certificate the server really presents:
subjectandsubjectAltName: the names it is valid for. Your site’s name must appear in the alternative names.issuer: who issued it. A browser trusts the issuer, not you.notBeforeandnotAfter: the validity window. Check the end date against today.
Always include -servername. Servers that host many sites on one address use it to decide which certificate to send, and leaving it out often returns a different, wrong certificate and sends you off in the wrong direction.
Then look at the chain and the verification result:
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | grep -E 's:|i:|Verify return code'
Verify return code: 0 (ok) means the chain checks out. Anything else tells you what failed: 20 (unable to get local issuer certificate) is the classic missing-chain error, 10 (certificate has expired) is self-explanatory, 18 or 19 mean a self-signed certificate. A second opinion from a different tool helps:
curl -vI https://example.com 2>&1 | grep -iE 'subject|issuer|expire|SSL certificate|verify'
Now match your symptom to the section below.
1. The certificate has expired
The certificate’s notAfter date is in the past. Everything else is a consequence. The question is why it was not renewed, and renewing by hand fixes today but not the cause.
Let’s Encrypt with Certbot. Check what Certbot believes and whether renewal works:
sudo certbot certificates
sudo certbot renew --dry-run
sudo systemctl list-timers | grep -i certbot
sudo tail -n 40 /var/log/letsencrypt/letsencrypt.log
The dry run exercises the whole renewal without changing anything and prints the real error. The usual causes:
- Port 80 is blocked or redirected badly. The default validation fetches a file over plain HTTP on port 80. A firewall rule, a security group, or a redirect that sends validation requests somewhere unexpected will fail it.
- The domain no longer points at this server. After a move, the old server cannot validate a name that now resolves elsewhere.
- A proxy or CDN is in the way. Validation must reach the origin. Either allow the validation path through, or use DNS validation, which does not need port 80.
- The renewal timer is gone. Check that a timer or cron job exists, and that it runs as root.
- A rate limit was hit. Let’s Encrypt limits failed validations and repeated issuance. If you retried many times, wait before the next try, and use the staging environment (
--staging) to test.
After renewing, reload the web server. A renewed file on disk does nothing until the server re-reads it:
sudo nginx -t && sudo systemctl reload nginx
sudo apachectl configtest && sudo systemctl reload apache2
A Certbot deploy hook can do this automatically after every renewal (--deploy-hook "systemctl reload nginx").
cPanel, Plesk and other panels. Use the panel’s own certificate tool. In cPanel the free certificates come from AutoSSL (WHM, Manage AutoSSL, which keeps logs of each run); in Plesk the Let’s Encrypt extension handles it per domain. If the automatic job fails, its log names the reason, and it is nearly always one of the DNS or port 80 causes above.
2. The name does not match
The browser says the certificate is valid for a different name, or “ERR_CERT_COMMON_NAME_INVALID”. Check subjectAltName in the output above. Typical causes:
wwwand the bare domain: the certificate coversexample.combut notwww.example.com, or the other way round. Request both names.- A subdomain was added later: a new
shop.example.comneeds to be on the certificate, or a wildcard (*.example.com) must cover it. A wildcard does not cover the bare domain and does not cover two levels deep. - The wrong site’s certificate is served. On a server with several sites, the one you asked for may have no
serverblock with its own certificate, so the default is served. Make sure each site has its ownssl_certificate(NGINX) or aVirtualHostwith its ownSSLCertificateFile(Apache), and test with-servername. - You connected by IP address. Certificates are issued for names, not addresses, so an IP always mismatches.
3. The chain is incomplete
This is the sneaky one, because it works in some places and fails in others. Desktop browsers often fix a missing intermediate certificate by themselves, so you test it in Chrome and it looks fine. Then curl, Java, Python, Android apps or a payment gateway’s callback refuse the connection with “unable to get local issuer certificate”.
The cause is that the server sends only the leaf certificate, not the intermediate that links it to the trusted root. The fix is to configure the full chain file:
For NGINX with Let’s Encrypt:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
fullchain.pem contains your certificate plus the intermediates; cert.pem contains only your certificate. Apache since 2.4.8 also takes the full chain in SSLCertificateFile. For a certificate bought from a commercial authority, concatenate in this order: your certificate first, then the intermediate(s), root last (the root is optional):
cat your_domain.crt intermediate.crt > fullchain.crt
Re-run s_client and look for Verify return code: 0 (ok).
4. The private key does not match the certificate
After a reissue, a server may refuse to start or reload with an error about key values mismatching. Compare the two:
openssl x509 -noout -modulus -in cert.pem | openssl md5
openssl rsa -noout -modulus -in privkey.pem | openssl md5
The two hashes must be identical. (For elliptic-curve keys, compare openssl x509 -noout -pubkey -in cert.pem with openssl pkey -pubout -in privkey.pem.) If they differ, you have mixed up files from different requests. Keep the certificate and its key together, and do not reuse the name of an old file for a new certificate.
5. Cloudflare, redirect loops and “SSL mode”
If your site sits behind Cloudflare, there are two separate connections: visitor to Cloudflare, and Cloudflare to your server. The SSL/TLS mode controls the second one:
- Flexible: Cloudflare talks to your server over plain HTTP. If your server then redirects HTTP to HTTPS, you get an endless redirect loop (“too many redirects”). Flexible should be avoided.
- Full: Cloudflare uses HTTPS to your server but does not check the certificate.
- Full (strict): it uses HTTPS and verifies a valid certificate on your server. This is the right setting, and it means your origin needs a real, unexpired, correctly named certificate (a Cloudflare Origin Certificate works for this).
Errors 525 and 526 (“SSL handshake failed”, “invalid SSL certificate”) mean exactly that the origin certificate is the problem, even though visitors see Cloudflare’s valid one. Test the origin directly, bypassing Cloudflare, with:
curl -vI --resolve example.com:443:203.0.113.10 https://example.com/
(replace the address with your server’s).
6. “Not secure”: mixed content
The certificate is fine, but the page loads some images, scripts or styles over http://. Browsers then show a warning or block those resources. Find them in the browser’s developer console (it lists each blocked address). On WordPress, the usual cause is old absolute URLs in the database, fixed with a safe search and replace:
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid --dry-run
Run it with --dry-run first; when the count looks right, run it again without. A Content-Security-Policy directive upgrade-insecure-requests is a useful safety net that asks browsers to fetch HTTP resources over HTTPS, but it does not replace fixing the addresses. Then add HSTS, starting with a short lifetime, once everything loads over HTTPS.
7. Old protocol versions and ciphers
If an old device or a security scanner complains, check which protocol versions the server offers:
nmap --script ssl-enum-ciphers -p 443 example.com
Modern setups serve TLS 1.2 and 1.3 only. Do not enable old versions to please one ancient client without understanding the trade: the broader your acceptance, the weaker the weakest connection.
A short routine that prevents most of this
- Alert on expiry. Check certificate end dates from outside and alert at 14 days (see the guide on monitoring a small server).
- Test renewal with
certbot renew --dry-runafter any change to the server, DNS, firewall or proxy. - Reload after renewal with a deploy hook.
- Serve the full chain, and check it with
openssl s_clientand a second client. - Cover every name you use, and review the list when you add a subdomain.
- Use Cloudflare’s Full (strict) if you use Cloudflare.
When it is worth getting help
Certificate problems are usually quick once you know which of the above you have, and expensive when they hit a checkout page or an API partner at the wrong moment. If renewals keep failing, if the chain or proxy setup confuses you, or if you want certificates and monitoring set up so you never think about it again, I can sort that out and document it.
You can see my profile on Upwork and send me the error you see, or read about server hardening. A broader checklist is in the Ubuntu server hardening checklist.