Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … x509: certificate is valid for a.example.com, not b.example.com

TLS hostname mismatch: 'certificate is valid for X, not Y'

The certificate's Subject Alternative Names don't include the hostname the client used.

Networking

What it means

Clients check that the hostname they connected to is in the certificate's SAN list (the Common Name is ignored by modern clients). Behind a shared IP, the server may also be sending the wrong certificate because of SNI.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. The certificate doesn't list that name

Check:

openssl s_client -connect host:443 -servername host </dev/null 2>/dev/null | openssl x509 -noout -ext subjectAltName

Fix: Reissue the certificate with every hostname as a SAN (or a wildcard that covers it).

2. The server returns the default certificate because the client sent no SNI, or the vhost is wrong

Check:

compare the output with and without -servername

Fix: Configure the certificate on the right virtual host, and use clients that send SNI.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors