What the browser checks
Browsers compare the address with the Subject Alternative Name (SAN) entries in the certificate. The Common Name (CN) has not counted for years; Chrome has ignored it since version 58. A certificate with only a CN and no SAN is therefore valid for no name. Firefox reports the error as SSL_ERROR_BAD_CERT_DOMAIN.
The most common causes
- www or bare domain missing. The certificate covers
www.example.com, the visitor opensexample.comor vice versa. - Wildcard limits.
*.example.comcoversshop.example.com, but neitherexample.comitself nora.b.example.com. - The wrong vhost answers. There is no matching
server_nameorServerNamefor the name. The server then uses the default vhost and its certificate. - DNS points to the wrong server. After a move a record still points to the old host or a CDN address without your certificate.
- Access by IP address or internal short name.
https://10.0.0.5orhttps://intranetonly match if exactly that is in the certificate.
Check
The SSL check shows all names in the certificate and marks whether the checked name is among them. On the command line, -servername matters, otherwise you may see a different certificate:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -ext subjectAltName
Whether DNS points to the right server is shown by the DNS lookup.
Fix
- Name missing from the certificate: reissue it with all names. With certbot:
certbot --nginx -d example.com -d www.example.com. For many subdomains, a wildcard via DNS validation; the ACME helper generates the commands. - Wrong vhost: in nginx every name must be in a
server_name, in Apache asServerNameorServerAliasin the<VirtualHost *:443>. Thennginx -torapachectl configtestand reload. - A redirect alone does not help: a redirect from
example.comtowwwonly applies after the TLS handshake. The redirected name needs a matching certificate too. - Internal servers: issue the certificate for the full name (FQDN) and use that, not the short name or the IP.
FAQ
Does a certificate for example.com also cover www.example.com?
No, unless both names are in the certificate. Let's Encrypt and most CAs include both if you request them.
Why does openssl show a different certificate than the browser?
Without -servername openssl sends no name (SNI) and gets the server’s default certificate. Browsers always send the name.
Can I get a certificate for an IP address?
From an internal CA, yes. Public certificates for IP addresses are offered by few CAs and usually with a short lifetime. A DNS name is simpler.