How to fix a certificate that does not cover the hostname

Get a certificate that names every hostname the site answers on, and make the server send it for each of them.

Last reviewed

Why it matters

Browsers accept a certificate only if one of its names matches the address being visited, and show a full-page security warning otherwise. The usual causes are a name never added to the certificate, such as www or a new subdomain, or a server sending its default certificate because no site matches the name.

How to fix it

See which names the certificate covers, for both example.com and www.example.com:

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

A wildcard such as *.example.com covers exactly one label: not example.com itself, and not a.b.example.com. Behind a CDN this shows the CDN's certificate; to see the origin's, connect to 203.0.113.10:443 with the same -servername.

Replace the highlighted values: example.com with your domain, www.example.com with the site's hostname, 203.0.113.10 with your origin server's IP address, example.com with the certificate's name, as `certbot certificates` shows it.

nginx

  1. Put every name in server_name for the listen 443 ssl block; when none matches, nginx sends the default server's certificate:
server {
    listen 443 ssl;
    server_name example.com www.example.com;
    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
}
  1. Get a certificate listing every name, one -d each. Each name's DNS must already point at this server, with the site reachable on port 80:
sudo certbot --nginx -d example.com -d www.example.com
  1. To change an existing certificate's names, list all the names to keep: --cert-name replaces the whole set.
sudo certbot certificates
sudo certbot certonly --cert-name example.com -d example.com,www.example.com
  1. Test and reload:
sudo nginx -t && sudo systemctl reload nginx

Sources: nginx: HTTPS servers, certbot user guide.

Apache

  1. In the <VirtualHost *:443> block set ServerName example.com and ServerAlias www.example.com. When nothing matches, Apache uses the first virtual host listed for that address and port, with its certificate.
  2. Issue a certificate for both names:
sudo certbot --apache -d example.com -d www.example.com
  1. Run apachectl configtest, then reload.

Sources: name-based virtual hosts, SSL how-to, certbot user guide.

Caddy

Caddy gets certificates only for the hostnames in its site addresses, so every name must appear in one. The names' DNS must point at the server, ports 80 and 443 must be reachable, and the data directory must persist:

www.example.com {
	redir https://example.com{uri}
}

example.com {
	# the site
}

Or serve both from one block, example.com, www.example.com { … }. Reload Caddy afterwards.

Sources: automatic HTTPS, Caddyfile patterns.

Cloudflare

  1. Cloudflare's certificate is served only for proxied records. For a DNS-only record visitors see the origin's certificate, so fix it at the origin.
  2. Universal SSL covers the apex and first-level subdomains (example.com, www.example.com), not deeper names such as dev.www.example.com. For those, use Advanced Certificate Manager (Total TLS, or an advanced certificate for the names) or upload a custom certificate.
  3. Check the status under SSL/TLS > Edge Certificates.
  4. With SSL mode Full (strict), the origin's certificate must also name the hostname, be in date, and come from a public authority or Cloudflare's Origin CA, or visitors get error 526.

Sources: Universal SSL, its limitations, Total TLS, Full (strict).

Shopify

Shopify issues free certificates for connected domains automatically, within 48 hours. If a name is missing or pending:

  1. In Settings > Domains, check the domain shows Connected.
  2. Check the DNS records: A @ to 23.227.38.65, AAAA @ to 2620:0127:f00f:5::, CNAME www to shops.myshopify.com. (other subdomains need only that CNAME). Keep exactly one A and one AAAA record, and no wildcard pointing at Shopify.
  3. On Cloudflare DNS, set every record pointing at Shopify to DNS only: Shopify does not support the proxy.
  4. If you have CAA records, allow letsencrypt.org, pki.goog and ssl.com.
  5. Turn off DNSSEC at your DNS provider if it is on. If the certificate is still pending after 48 hours, contact Shopify Support.

Sources: Shopify: secure connections, troubleshoot domains, connect a domain manually.

Vercel

Vercel issues a certificate for every domain added to the project, and none for a name that is not.

  1. Project > Settings > Domains > Add Existing, and add both example.com and www.example.com.
  2. Set the redirect: Edit the domain and pick a target under Redirect to.
  3. Configure DNS as the dashboard shows, so requests reach Vercel; if you have CAA records, allow Let's Encrypt.
  4. Confirm with the domain's status in Settings > Domains, or vercel certs list.

Sources: add a domain, redirecting, SSL.

Netlify

  1. Adding either the apex or www adds both, so point both at Netlify: the apex with an ALIAS, ANAME or flattened CNAME to apex-loadbalancer.netlify.com (or an A record to 75.2.60.5), and www with a CNAME to the site's netlify.app address.
  2. Add any other name under Domain management > Production domains > Add domain alias. Aliases join the certificate only if their DNS already points at Netlify when it is issued.
  3. Provisioning is blocked by more than one A record on the apex, leftover AAAA records, DNSSEC, or CAA records that do not allow Let's Encrypt.
  4. Check the status under Domain management > HTTPS.

Sources: HTTPS on Netlify, troubleshooting, external DNS, domain aliases.

Check that it worked

  1. Run the openssl … -ext subjectAltName command again for every hostname you serve: each must be listed, exactly or under a one-label wildcard.
  2. Open https://www.example.com/ in a private window and confirm there is no warning.
  3. Run the Owl Keeper Certificate check again.

Test it now with the free SSL certificate checker. No account needed.

What can go wrong

  • Pointing DNS somewhere new to validate a name moves real traffic. Check what answers on that name now (mail, an old app, another service) before you change it, and the same before switching a Cloudflare record between proxied and DNS only.
  • certbot --cert-name with a shorter list removes names, which stop being covered at the next reload.
  • Changing server_name, ServerName or the order of virtual hosts can change which site unmatched hostnames receive.
  • CAA and DNSSEC changes affect every service on the domain.