Browser errors

SSL_ERROR_BAD_CERT_DOMAIN: certificate not valid for this name

By · Last verified

Error messageSSL_ERROR_BAD_CERT_DOMAIN

SSL_ERROR_BAD_CERT_DOMAIN means the site's certificate was issued for a different hostname than the one you are visiting. The certificate itself may be valid; it does not cover this name. This is almost always fixed on the server.

Is it the site or your device?

Almost always the site; a captive portal or proxy is the rare local cause. Look at the certificate's names with the SSL checker:

curl ssl.sh/example.com

If the hostname is missing from the SAN list, the site owner must fix it. If the checker shows the right certificate but Firefox does not, suspect your network: a public Wi-Fi login page, a DNS filter, a hosts-file entry, or a proxy that answers on behalf of other sites. Also check for typos and old bookmarks pointing to a retired hostname.

Causes

1. www or bare domain missing

The certificate covers example.com but not www.example.com, or the reverse. Inspect the names:

echo | openssl s_client -connect example.com:443 -servername www.example.com 2>/dev/null \
  | openssl x509 -noout -ext subjectAltName

2. Wildcard does not match

*.example.com covers one label only. It does not match example.com or dev.api.example.com.

3. Shared hosting or SNI falls back to the default site

When no server block matches the requested name, the server presents its default certificate, which belongs to another site. This often happens after adding a domain to DNS before configuring the web server.

4. CDN or load balancer without a certificate for the name

Edge servers return a generic certificate when none is bound to the hostname. Attach a certificate covering each accelerated name.

5. Visiting by IP address or internal name

Typing https://203.0.113.10 or a short intranet name rarely matches a certificate. Use the full hostname the certificate was issued for.

What it looks like in each browser

Browser What you see
Firefox "Warning: Potential Security Risk Ahead" and "uses a certificate that is not valid for example.com"
Chrome / Edge NET::ERR_CERT_COMMON_NAME_INVALID
Safari "This Connection Is Not Private"
curl no alternative certificate subject name matches target host name

How site owners fix it

A certificate that lists every hostname, mapped to the right server block, fixes it.

1. Include every hostname in one certificate. Request all names your visitors use:

sudo certbot certonly --nginx -d example.com -d www.example.com

If you need a CSR for a commercial CA, the CSR generator adds the SAN entries for you.

2. Map each name to the right server block.

server {
    listen 443 ssl;
    server_name example.com www.example.com;
    ssl_certificate     /etc/nginx/ssl/example.com.fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/example.com.key;
}

3. Check every endpoint after the change with curl ssl.sh/example.com and curl ssl.sh/www.example.com, then add a 301 redirect to your preferred hostname.

FAQ

Can I add an exception for SSL_ERROR_BAD_CERT_DOMAIN?

Firefox allows it unless the site uses HSTS, but an exception only makes sense for a device you own reached by IP or a local name. On public sites a wrong-name certificate can mean you are talking to the wrong server.

Why do I only see this on hotel or airport Wi-Fi?

The network's login page intercepts your request and answers with its own certificate. Log in to the Wi-Fi first; see captive portal SSL errors.

Does a certificate for example.com cover www.example.com?

Only if www.example.com is also listed in the SAN extension. Most CAs add both names when you order one, but ACME clients only include the names you request.

The error appeared right after I moved my site to a CDN. What changed?

Visitors now reach the CDN edge instead of your origin, and the edge presents whatever certificate is bound to that hostname in the CDN account. If you have not issued or uploaded one, the edge falls back to a shared default certificate for another name. Bind a certificate covering every accelerated hostname, then confirm with curl ssl.sh/example.com that the edge, not the origin, serves the right one.

Sources

  1. Mozilla Support: Error codes on secure websites
  2. RFC 9525: Service Identity in TLS
  3. RFC 6066 section 3: Server Name Indication