NET::ERR_CERT_COMMON_NAME_INVALID: Diagnosing and Fixing TLS Hostname Mismatches
What NET::ERR_CERT_COMMON_NAME_INVALID Actually Means
NET::ERR_CERT_COMMON_NAME_INVALID is Chromium’s error code for a TLS hostname mismatch. The certificate itself may be perfectly valid — correctly signed, unexpired, properly chained — but the name the browser asked for is not listed in the certificate the server presented.
Chrome spells it out in the details panel: “This server could not prove that it is a.example.com; its security certificate is from example.com. This may be caused by a misconfiguration or an attacker intercepting your connection.” Firefox reports the same condition as SSL_ERROR_BAD_CERT_DOMAIN; Safari shows a generic “This Connection Is Not Private” warning.
The name of the error is historical. Since Chrome 58 and Firefox 48, browsers ignore the Common Name (CN) field entirely and validate only the subjectAltName (SAN) extension. A certificate that carries the right name in CN but no SAN will still fail — a detail that trips up people working with old internal CAs and self-signed certificates.
Typical triggers:
- You requested
a.example.com, but the certificate covers onlyexample.com. - A subdomain was added later and nobody reissued the certificate.
- A wildcard
*.example.comis being used for a deeper name likeapi.eu.example.com. - DNS points at a load balancer, CDN, or ingress controller that falls back to a default certificate when SNI does not match any configured virtual host.
- You are reaching the site by IP address, but the certificate has no
iPAddressSAN entry.
Distinguish it from neighbouring errors before you start changing anything: ERR_CERT_AUTHORITY_INVALID means the chain is untrusted (missing intermediate or private CA), ERR_CERT_DATE_INVALID means expiry, and ERR_SSL_VERSION_OR_CIPHER_MISMATCH means the handshake never got as far as certificate validation.
How Hostname Verification Works Today: CN, SAN, and Wildcards
Hostname matching follows RFC 6125 and the CA/Browser Forum Baseline Requirements. The rules that matter in practice:
- Only SAN entries count. CN is displayed for humans and ignored for validation. A cert must contain at least one
DNS:oriPAddress:entry. - Wildcards match exactly one label, on the leftmost position only.
*.example.commatchesa.example.comandwww.example.com, but it does not matchexample.comitself, and it does not matcha.b.example.com. - Multi-level wildcards such as
*.*.example.comare not issued by public CAs. If you need arbitrary depth, enumerate names or restructure your DNS. - IDNs are compared in A-label (punycode) form. A certificate for
xn--bcher-kva.examplematchesbücher.examplein the URL bar, and vice versa — but a certificate issued for the U-label without the A-label will not. - SNI decides which certificate you get. Certificate selection happens during the handshake, before any HTTP request exists. The server picks a cert based on the
server_nameextension the client sends. If the client sends no SNI, or an SNI the server has no vhost for, you get the default certificate — usually a mismatch. - Ports and paths are irrelevant. Only the hostname in the URL is compared.
This is also why an HTTP redirect can never fix this error: the handshake fails before a single byte of HTTP — including a 301 — can be exchanged.
Step 1 — Confirm What the Certificate Actually Covers
Always inspect the certificate the server actually serves for that hostname, not the one you think you installed.
openssl s_client -connect a.example.com:443 -servername a.example.com
</dev/null 2>/dev/null
| openssl x509 -noout -subject -issuer -dates -ext subjectAltName
Expected output looks like:
subject=CN = example.com
issuer=C = US, O = Let's Encrypt, CN = R3
notBefore=Feb 1 00:00:00 2025 GMT
notAfter=May 2 23:59:59 2025 GMT
X509v3 Subject Alternative Name:
DNS:example.com, DNS:www.example.com
If a.example.com is missing from that SAN line, you have found the cause. Three more checks worth running immediately:
# 1. Ask OpenSSL to do the verification for you (OpenSSL 1.1.0+)
openssl s_client -connect a.example.com:443 -servername a.example.com
-verify_hostname a.example.com -verify_return_error </dev/null
# success: "Verify return code: 0 (ok)"
# failure: "verify error:num=62:hostname mismatch"
# 2. Test a local certificate file against a hostname
openssl x509 -in /etc/letsencrypt/live/example.com/cert.pem
-noout -checkhost a.example.com
# "Hostname a.example.com does match certificate" / "does NOT match certificate"
# 3. What does curl think?
curl -vI https://a.example.com 2>&1 | grep -E 'subject:|subjectAltName|SSL certificate|error'
To check several names at once:
for h in example.com www.example.com a.example.com api.eu.example.com; do
printf '%-24s ' "$h"
echo | openssl s_client -connect "$h:443" -servername "$h" -verify_hostname "$h" 2>&1
| grep -E 'Verify return code' || echo 'no TLS response'
done
If the hostname does not resolve yet — for example during a migration — force the connection to the new IP while keeping the SNI and hostname check intact:
curl --resolve a.example.com:443:203.0.113.10 -vI https://a.example.com
openssl s_client -connect 203.0.113.10:443 -servername a.example.com </dev/null
Drop the -servername flag and you will see the default certificate instead — a quick way to prove that SNI-based selection is what is returning the wrong cert.
Which Certificate Do You Actually Need?
Once you know the set of hostnames that must work, pick the cheapest certificate shape that covers them — and remember the wildcard boundaries.
| Certificate type | Example SAN entries | Matches | Does NOT match |
|---|---|---|---|
| Single domain | DNS:example.com |
example.com |
www.example.com, a.example.com |
| Multi-domain (SAN / UCC) | DNS:example.com, DNS:www.example.com, DNS:a.example.com |
Every listed name | Any unlisted name |
| Wildcard | DNS:*.example.com |
a.example.com, www.example.com |
example.com, a.b.example.com |
| Wildcard + apex | DNS:*.example.com, DNS:example.com |
Apex plus exactly one label deep | a.b.example.com |
| Multi-level wildcard | DNS:*.*.example.com |
Two labels deep | Not publicly issuable — plan around it |
| IP certificate | iPAddress:203.0.113.10 |
https://203.0.113.10/ |
Any DNS name pointing at that IP |
Rule of thumb: if you have more than three or four one-level subdomains under a single parent, a wildcard is simpler to operate. If your names are spread across different registrable domains or you need deeper levels, use a multi-domain certificate with an explicit SAN list.
Fixing the Mismatch: Reissue, Reconfigure, or Re-route
There are only three legitimate fixes. Pick based on whether the hostname is supposed to exist.
Option A — The hostname is legitimate: add it to the certificate
# Expand an existing Let's Encrypt certificate with an extra name
sudo certbot certonly --webroot -w /var/www/html
-d example.com -d www.example.com -d a.example.com --expand
# List what certbot currently manages and which names each covers
sudo certbot certificates
# Wildcard requires DNS-01; HTTP-01 cannot issue wildcards
sudo certbot certonly --manual --preferred-challenges dns
-d '*.example.com' -d example.com
For automated wildcard renewal, use a DNS plugin instead of --manual, e.g. --dns-cloudflare --dns-cloudflare-credentials ~/.secrets/cloudflare.ini. Then reload the web server:
sudo certbot renew --dry-run
sudo systemctl reload nginx # or: sudo apachectl graceful
Option B — The hostname should not be served here: remove it from DNS
If a.example.com is an old, decommissioned name still pointing at the server, delete or repoint the record. Any name that resolves to an IP address must be covered by a certificate served on that IP, or users will see this error.
Option C — Consolidate onto a covered name
If the certificate cannot be changed (third-party SaaS, fixed appliance), make the application link to a hostname that is covered, or set up an HTTP-only redirect from the uncovered name — accepting that HTTPS to the uncovered name will still fail at the handshake.
Server Configuration Patterns That Cause Mismatches
A correct certificate installed in the wrong virtual host produces exactly this error. Start by dumping the effective configuration.
sudo nginx -T | grep -nE 'server_name|ssl_certificate '
sudo apachectl -S
sudo ss -tlnp | grep ':443'
Nginx
Each TLS hostname needs a server block whose server_name matches the SNI value and whose certificate covers that name.
server {
listen 443 ssl;
server_name a.example.com;
ssl_certificate /etc/letsencrypt/live/a.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/a.example.com/privkey.pem;
# ...
}
Everything that does not match a server_name falls through to the default_server block for that port. If the default block serves the example.com certificate, every unconfigured name on that IP gets a mismatch. Point the default block at a certificate that covers the names you cannot remove, or return a bare close:
server {
listen 443 ssl default_server;
server_name _;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
return 444;
}
Apache
<VirtualHost *:443>
ServerName a.example.com
ServerAlias www.a.example.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/a.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/a.example.com/privkey.pem
</VirtualHost>
ServerAlias entries must all appear in the certificate’s SAN list; Apache will happily serve the vhost for an alias the certificate does not cover.
Load balancers, CDNs, and ingress controllers
The same default-certificate logic applies at the edge. Common patterns: a Kubernetes Ingress with one TLS secret shared by several hosts; a CDN origin configured with a single certificate while the edge hostname is different; a cloud load balancer with a listener default certificate that does not include the newly added hostname. Check the certificate as served by the edge, not by the origin, with the openssl s_client command above.
Troubleshooting: Real Error Messages Decoded
| Client / tool | Message you will see | Meaning and fix |
|---|---|---|
| Chrome / Edge | NET::ERR_CERT_COMMON_NAME_INVALID — “its security certificate is from example.com” |
URL hostname absent from SAN. Reissue with the name added, or stop resolving that name to this server. |
| Firefox | SSL_ERROR_BAD_CERT_DOMAIN |
Same condition. Check for a proxy or AV product terminating TLS with its own certificate. |
| curl | curl: (60) SSL: no alternative certificate subject name matches target host name 'a.example.com' |
Definitive SAN mismatch. Re-run with -v to see the served cert, then reissue. |
| OpenSSL | verify error:num=62:hostname mismatch / Verify return code: 62 (hostname mismatch) |
Use -servername and -verify_hostname together; a missing -servername gives you the default cert and a false positive. |
| Python requests | ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'a.example.com'. |
Same root cause. Never “fix” it with verify=False in production. |
| Node.js | Error: Hostname/IP does not match certificate's altnames: Host: a.example.com. is not in the cert's altnames: DNS:example.com |
Explicit SAN dump in the message — usually enough to diagnose without further tooling. |
| Go | x509: certificate is valid for example.com, not a.example.com |
Go prints the full valid-name list; compare against your intended hostname. |
| Java | java.security.cert.CertificateException: No subject alternative DNS name matching a.example.com found. |
Trust store is fine; the name is not in SAN. Check for a JVM-level proxy or a wrong Host header. |
| Any client | Certificate covers the name but error persists | You are hitting a different backend than you think — verify DNS (dig +short a.example.com) and compare with the IP returned by curl -vI. |
Two false alarms are worth ruling out early. First, a corporate TLS-inspecting proxy replaces the certificate with its own; if the issuer in the error is your security vendor, the mismatch is on the proxy, not your server. Second, HSTS converts a click-through-able warning into a hard failure — once a domain is on the HSTS preload list, users cannot bypass the interstitial at all, which turns a misconfiguration into a full outage for that hostname.
Preventing Regressions: Pre-Deploy and Monitoring Checks
Add a hostname assertion to CI so a certificate swap or a new subdomain cannot ship silently broken.
#!/usr/bin/env bash
set -euo pipefail
HOSTS="example.com www.example.com a.example.com"
for h in $HOSTS; do
if openssl s_client -connect "$h:443" -servername "$h" -verify_hostname "$h"
-verify_return_error </dev/null 2>&1 | grep -q 'Verify return code: 0 (ok)'; then
echo "OK $h"
else
echo "FAIL $h" >&2
exit 1
fi
done
Also worth scheduling:
certbot renew --dry-runin a weekly job, so renewal breakage is caught 30 days before expiry rather than on the day.- An inventory of every DNS name pointing at each public IP, reconciled against the SAN lists of the certificates served there. Most of these errors come from names nobody remembered existed.
- An alert on the certificate’s
notAfterdate per hostname, not per certificate file — the two diverge when the wrong file is deployed.
FAQ
Is the Common Name field still used for validation?
No. Chrome 58+, Firefox 48+, and current versions of curl, Go, Java, and Python ignore CN and match only against subjectAltName. If a certificate has a CN but no SAN extension, every modern client rejects it with this error. Reissue with SAN entries.
Does *.example.com cover example.com?
No. A wildcard matches one label to the left of the parent, never the parent itself. You need both DNS:example.com and DNS:*.example.com on the certificate — most CAs issue them together at no extra cost.
Does *.example.com cover a.b.example.com?
No. Wildcards match exactly one label. Public CAs will not issue *.*.example.com, so either enumerate the deeper names in SAN or flatten your DNS naming.
Why does it work in curl but fail in Chrome?
They may be reaching different backends (split-horizon DNS, VPN, proxy), or Chrome may be using a cached connection or an HTTP/3 path to a different edge node. Compare the certificate issuer and SAN in both clients with openssl s_client and Chrome’s lock-icon → Certificate → Subject Alternative Name panel.
Can I bypass the warning by clicking “Proceed”?
Only on non-HSTS domains, and only for yourself — never for users. On HSTS-protected domains the interstitial has no bypass at all, and the browser will refuse the connection outright.
Will an HTTP-to-HTTPS redirect fix it?
No. The TLS handshake completes — or fails — before any HTTP request is sent, so a redirect cannot be delivered to a client that has already rejected the certificate. The fix must be a certificate change or a DNS change.
I access the server by IP. Why does it still fail?
Hostname verification applies to IP literals too, and requires an iPAddress SAN entry. A certificate with only DNS: entries will never match https://203.0.113.10/. Either add the IP SAN or use a DNS name.
What about a trailing dot, like a.example.com.?
Browsers and most libraries normalise the trailing root dot, but some HTTP clients and older TLS stacks do not, producing a mismatch on an otherwise correct certificate. Strip trailing dots in application-level URL handling.
Does changing the port affect the check?
No. The port is not part of the hostname comparison. https://a.example.com:8443/ validates against the same SAN entries as port 443.