nginx.ccWeb server troubleshooting desk
Home / Errors / emerg
emerg

nginx cannot load certificate: missing file or key mismatch

Short answer

nginx -t reporting “cannot load certificate … No such file or directory” most often means ssl_certificate was written before the certificate existed (chicken and egg); “key values mismatch” means the certificate and key are not a pair. For a new site issue the certificate with an HTTP-only config first, then switch to HTTPS; for a mismatch compare the public keys with openssl.

Most common cause: A new site used the full HTTPS config before the certificate was issued.

Try this first: Issue over HTTP first, then switch to HTTPS

server {
    listen 80;
    server_name example.com;
    location /.well-known/acme-challenge/ { root /var/www/_letsencrypt; }
}
# certbot certonly --webroot -w /var/www/_letsencrypt -d example.com
# once issued, add listen 443 ssl and ssl_certificate

Last verified: · against the official docs listed below · Sources

Typical log lines

nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/example.com/fullchain.pem": BIO_new_file() failed (SSL: error:80000002:system library::No such file or directory…)
nginx: [emerg] SSL_CTX_use_PrivateKey("/etc/ssl/private/example.key") failed (SSL: error:05800074:x509 certificate routines::key values mismatch)

Common causes

  1. A new site used the full HTTPS config before the certificate was issued.
  2. Wrong path: the live/ directory got a -0001 suffix (certbot creates a new one when issuing again).
  3. The certificate was renewed but the old key is still configured, or another domain's key was used.
  4. nginx cannot read the key file (mode 600 with the wrong owner).

Diagnosis commands

The real certificate directory names
#ls -l /etc/letsencrypt/live/
Certificates and paths certbot manages
#certbot certificates
The hashes must match
#openssl x509 -noout -pubkey -in fullchain.pem | sha256sum; openssl pkey -pubout -in privkey.pem | sha256sum

Fix configs

Issue over HTTP first, then switch to HTTPS

server {
    listen 80;
    server_name example.com;
    location /.well-known/acme-challenge/ { root /var/www/_letsencrypt; }
}
# certbot certonly --webroot -w /var/www/_letsencrypt -d example.com
# once issued, add listen 443 ssl and ssl_certificate

Reference the certificate and key as a pair

ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

Run nginx -t first, then systemctl reload nginx.

Key facts and sources

  • ssl_certificate names a PEM certificate; intermediates belong in the same file after the server certificate. [nginx.org]
  • Certbot's webroot plugin writes challenge files to <webroot>/.well-known/acme-challenge/. [eff-certbot.readthedocs.io]

Checked against the linked pages on 2026-11-14; the official docs win if a newer nginx changes them.

FAQ

Why does certbot --nginx fail as well?

certbot needs nginx running, and nginx cannot start without the certificate. Comment out the 443 server or use the stage-1 config first.

cert.pem or fullchain.pem?

fullchain.pem. cert.pem lacks the intermediate, so some clients reject it.

Fix it with a tool

Related errors

Sponsored slot (empty)
VPS / CDN recommendations may appear here later, labelled as affiliate links. There are no referral links today.