nginx cannot load certificate key (PEM_read_bio_PrivateKey)
Fix nginx cannot load certificate key by the function in brackets: BIO_new_file is path or permissions; PEM_read_bio_PrivateKey is wrong file or passphrase.
nginx: [emerg] cannot load certificate key "/etc/nginx/ssl/example.com.crt": PEM_read_bio_PrivateKey() failed (SSL: error:1E08010C:DECODER routines::unsupported:No supported data to decode. Input type: PEM)nginx could not read the file in ssl_certificate_key as a private key. The first function name in the brackets, plus the text after it, tells you why. BIO_new_file() means the file could not even be opened (path or permissions). PEM_read_bio_PrivateKey() means it opened but did not parse as a key (wrong content or a passphrase-protected key). The example above has the certificate file in the key slot.
[1] Pick the branch from the text in brackets. Every message below was reproduced one at a time in the same container.
| In brackets | Cause | Go to |
|---|---|---|
BIO_new_file() failed … No such file or directory | Typo in the path, missing file | [2] |
BIO_new_file() failed … Permission denied | nginx -t or nginx run as a non-root user | [5] |
PEM_read_bio_PrivateKey() failed … No supported data to decode | No key in the key file (a certificate, for example) | [3] |
PEM_read_bio_PrivateKey() failed … problems getting password · bad password read | Passphrase-protected key | [4] |
When the key and certificate simply do not belong together you get key values mismatch instead; see key values mismatch.
[2] If the file is reported missing, list the directory from the exact path in the error. The reproduction said "/etc/nginx/ssl/example.com.pem": BIO_new_file() failed.
# ls -l /etc/nginx/ssltotal 16-rw-r--r-- 1 root root 1119 … example.com.crt-rw------- 1 root root 1886 … example.com.enc.key-rw------- 1 root root 1704 … example.com.key-rw------- 1 root root 10 … example.com.passThe configuration says .pem but the file is .key. For a symlink, use ls -lL to confirm the target exists. With Let's Encrypt the key is /etc/letsencrypt/live/<domain>/privkey.pem.
[3] If the file exists and you see No supported data to decode, check the first line.
# head -1 /etc/nginx/ssl/example.com.crt /etc/nginx/ssl/example.com.key==> /etc/nginx/ssl/example.com.crt <==-----BEGIN CERTIFICATE----- ==> /etc/nginx/ssl/example.com.key <==-----BEGIN PRIVATE KEY-----A key file starts with BEGIN PRIVATE KEY, BEGIN RSA PRIVATE KEY or BEGIN EC PRIVATE KEY. BEGIN CERTIFICATE means the two files were swapped between ssl_certificate and ssl_certificate_key. To test a key without nginx, run openssl pkey -in <key file> -noout && echo OK. In the reproduction the key file printed OK and the certificate file printed Could not find private key of key from ….
[4] problems getting password means the key has a passphrase. Its first line looks like this:
# head -1 /etc/nginx/ssl/example.com.enc.key-----BEGIN ENCRYPTED PRIVATE KEY-----Without a password file, nginx -t ended like this (the container had no terminal to type into):
# nginx -tEnter PEM pass phrase:Enter PEM pass phrase:…nginx: [emerg] cannot load certificate key "/etc/nginx/ssl/example.com.enc.key": PEM_read_bio_PrivateKey() failed (SSL: … problems getting password … bad password read)nginx: configuration file /etc/nginx/nginx.conf test failedEven if typing the passphrase at a terminal gets you through, there is nowhere to type it when systemd starts nginx. Put the passphrase in a file, one per line, and point ssl_password_file at it (nginx 1.7.3 and later; multiple lines are tried in turn).
ssl_certificate /etc/nginx/ssl/example.com.crt; ssl_certificate_key /etc/nginx/ssl/example.com.enc.key; ssl_password_file /etc/nginx/ssl/example.com.pass;The password file is plain text, so give it chmod 600 like the key (the reproduction used 600). Then test again:
# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[5] Permission denied shows up when nginx runs as a non-root user. In the reproduction the key was root-owned with mode 600, and nginx -t as root passed. Testing the same files as the nginx user gave this:
# su -s /bin/sh nginx -c "nginx -t"…2026/10/27 03:50:41 [emerg] 17#17: cannot load certificate key "/etc/nginx/ssl/example.com.key": BIO_new_file() failed (SSL: error:8000000D:system library::Permission denied … )nginx: configuration file /etc/nginx/nginx.conf test failedIf you ran nginx -t from a normal account, prefix it with sudo. In the usual setup (the master starts as root and the user directive applies only to workers), the master reads the key as root, so do not change the key's owner. Doing so lets the worker account read the key too.
Change the owner only when the master process itself runs as a non-root account (an unprivileged nginx image, a container with USER set, and so on). Record the current owner and mode first so you can put them back:
# stat -c '%U:%G %a' /etc/nginx/ssl/example.com.key# chown <account that starts nginx> /etc/nginx/ssl/example.com.keyTo roll back (if stat showed root:root 600):
# chown root:root /etc/nginx/ssl/example.com.key && chmod 600 /etc/nginx/ssl/example.com.keyOpening the key up to 644 lets every account read it, so do not use that as the fix.
[6] After the fix, reload with nginx -t && systemctl reload nginx. If key values mismatch appears next, the key was read but belongs to a different certificate. The HAProxy side of the same problem is in HAProxy unable to load SSL private key.
Analyze your Nginx log in the browser ↗ — nothing is uploaded.
Check it with the Certificate (PEM · X.509) decoder tool ↗ — calculated in your browser.