Nginx: no ssl_certificate is defined for the ssl listener
What "no ssl_certificate is defined for the ssl listener" actually means
This is a configuration-resolution error, not a file error. Nginx parses the config, sees a socket declared as SSL, and cannot find a certificate directive that applies to that server block. It never even opens the certificate file, so permissions, SELinux and file contents are not the cause of this specific message — those produce different errors further down.
You will see one of two spellings depending on the nginx build:
- Legacy wording (older distro builds):
nginx: [emerg] no ssl_certificate is defined for the ssl listener - Current wording (1.11+):
nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/conf.d/example.conf:5
The listen ... ssl in the modern message is a literal placeholder — nginx prints the directive form, not the port. Trust the file:line suffix instead.
The error is raised whenever a block contains any of these and has no resolvable certificate:
listen 443 ssl;/listen [::]:443 ssl;listen 443 ssl http2;(deprecated form on 1.25.1+)listen 8443 ssl;— any port, not just 443ssl on;on legacy configs (deprecated since 1.15.0)- A
serverblock markeddefault_serverthat also carriesssl
Five-minute triage: locate the offending server block
Always start with the config test. It prints the exact file and line:
sudo nginx -t
Then dump the merged configuration. This is the only reliable view because it shows what nginx actually parsed after all include globs were expanded:
sudo nginx -T 2>/dev/null | grep -n -A12 'listen.*ssl'
sudo nginx -T 2>/dev/null | grep -nE 'ssl_certificate|ssl_certificate_key'
Two failure modes hide here:
- The block with
listen 443 sslis real, but the certificate lives in a differentserverblock. Directives are not shared between sibling server blocks. - The file you edited is not included at all.
include /etc/nginx/conf.d/*.conf;will not matchexample.conf.bak,example.conf.disabled, or files in a directory nobody includes. Ifgrep -c ssl_certificateon thenginx -Toutput returns 0, you edited a file nginx never read.
If the service is already running and you are debugging a reload, also check:
sudo systemctl status nginx --no-pager
sudo journalctl -u nginx -n 50 --no-pager
The minimal correct configuration
Both directives are mandatory. A key without a certificate, or a certificate without a key, still aborts startup.
server {
listen 443 ssl;
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;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
root /var/www/example.com;
index index.html;
}
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
Rules that prevent 90% of repeats of this error:
- Same block.
ssl_certificatemust sit in the block that owns thelisten ... ssl, or in an enclosinghttpblock it can inherit from. - Absolute paths only. Relative paths resolve against the nginx prefix (
/etc/nginxon Debian/Ubuntu,/usr/share/nginxon RHEL family), which is rarely what you want. - Full chain for the cert. The file referenced by
ssl_certificateshould be leaf certificate first, then intermediates. The root is not needed. - RSA + ECDSA dual certs are supported since 1.11.0 by repeating
ssl_certificate/ssl_certificate_keypairs — one pair per algorithm. - Private key hygiene:
chmod 600and owned by root is fine; nginx master reads it as root before dropping privileges.
Verify paths, permissions, and SELinux context
Once the directive is present, the next class of failures is file access. Check every path component, not just the leaf file — a drwx------ on the containing directory is the classic culprit:
sudo namei -l /etc/nginx/ssl/example.com.fullchain.pem
sudo -u nginx test -r /etc/nginx/ssl/example.com.key && echo readable || echo NOT-readable
On RHEL, CentOS, Rocky, Alma and Fedora, also check the SELinux label. Permissions can be perfect while the label still blocks the read:
sudo ls -lZ /etc/nginx/ssl/
sudo restorecon -Rv /etc/nginx/ssl/
If certificates live outside /etc/nginx (for example /etc/pki/nginx), you must teach SELinux about the location once, then relabel:
sudo semanage fcontext -a -t httpd_config_t "/etc/pki/nginx(/.*)?"
sudo restorecon -Rv /etc/pki/nginx
Confirm the files are actually usable PEM, and that the pair matches:
openssl x509 -in /etc/nginx/ssl/example.com.fullchain.pem -noout -subject -issuer -dates
openssl pkey -in /etc/nginx/ssl/example.com.key -check -noout
diff <(openssl x509 -in /etc/nginx/ssl/example.com.fullchain.pem -noout -pubkey)
<(openssl pkey -in /etc/nginx/ssl/example.com.key -pubout)
No output from diff means the certificate and key belong together.
Version caveats: variable paths, http2, and the deprecated ssl directive
- Variables in certificate paths (
$ssl_server_name,$host) require a modern mainline build — the feature landed in the 1.15.x series (1.15.9). It is absent from 1.14 stable and older. Check withnginx -Vbefore copying a dynamic-SNI snippet. - When a certificate path contains variables, nginx cannot validate it at startup.
nginx -tpasses, and failures only appear at handshake time as connection resets orSSL_do_handshake() failedin the error log. Do not rely on-talone in that setup. ssl on;is deprecated since 1.15.0 and emits[warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead. Convert tolisten 443 ssl;.listen 443 ssl http2;is deprecated since 1.25.1; uselisten 443 ssl;plus a separatehttp2 on;.- If you get
[emerg] unknown directive "ssl_certificate", the build has nohttp_ssl_moduleat all. Confirm withnginx -V 2>&1 | tr ' ' 'n' | grep http_ssl_moduleand reinstall from your distro’s full nginx package.
Cause-to-fix comparison table
| Error text | Root cause | Detection | Fix |
|---|---|---|---|
no "ssl_certificate" is defined for the "listen ... ssl" directive |
listen ... ssl present, no cert directive in that block |
nginx -T | grep -n -A12 'listen.*ssl' |
Add ssl_certificate + ssl_certificate_key |
| Same message, but you can see the directive in the file | File not included by any include glob |
nginx -T | grep -c ssl_certificate |
Rename to *.conf, fix the include path |
| Same message, cert exists in a sibling block | Directive scoping — siblings do not share | nginx -T, compare block boundaries |
Move directive into the correct block, or to http |
BIO_new_file() failed ... Permission denied |
Filesystem mode or SELinux label | namei -l, ls -lZ, ausearch -m avc -ts recent |
chmod/chown + restorecon -Rv |
BIO_new_file() failed ... no such file |
Typo, wrong absolute path, cert not deployed | ls -l <path> |
Correct the path or copy the file |
PEM_read_bio_X509_AUX() failed ... no start line |
Wrong file type (key passed as cert, DER, empty file) | head -1 cert.pem |
Point to the PEM certificate / full chain |
PEM_read_bio_PrivateKey() failed ... unsupported |
Passphrase-protected key, PKCS#12 or DER key | head -1 key.pem |
Decrypt or convert to unencrypted PEM |
SSL_CTX_use_PrivateKey() failed ... EVP lib |
Certificate and key do not match | Compare -pubkey / -pubout output |
Reissue or re-download the matching pair |
unknown directive "ssl_certificate" |
nginx built without http_ssl_module |
nginx -V 2>&1 | grep http_ssl_module |
Install the full nginx package |
"ssl_certificate" directive is duplicate |
Directive set twice in the same block | nginx -T | grep -n ssl_certificate |
Keep one pair (or one pair per algorithm) |
Troubleshooting: real error messages and what to do
1. The headline error, with a file and line
nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/conf.d/example.conf:5
Open /etc/nginx/conf.d/example.conf, go to line 5, and add the two certificate directives to that same server block. Then re-run sudo nginx -t.
2. Certificate exists but cannot be opened
nginx: [emerg] cannot load certificate "/etc/nginx/ssl/example.com.crt": BIO_new_file() failed (SSL: error:8000000D:system library::Permission denied:calling fopen(/etc/nginx/ssl/example.com.crt, r))
Root can read it, nginx cannot. Check the whole path with namei -l, then relabel: sudo restorecon -Rv /etc/nginx/ssl/. If a denial persists, confirm with sudo ausearch -m avc -ts recent | grep nginx.
3. Encrypted or non-PEM private key
nginx: [emerg] cannot load certificate key "/etc/nginx/ssl/example.com.key": PEM_read_bio_PrivateKey() failed (SSL: error:1E08010C:DECODER routines::unsupported)
nginx never prompts for a passphrase. Either strip it — openssl pkey -in example.com.key -out example.com.unencrypted.key — or point ssl_password_file at a chmod 600 file containing the passphrase. If the key is PKCS#12, extract it: openssl pkcs12 -in bundle.pfx -nocerts -nodes -out example.com.key.
4. Certificate and key mismatch
nginx: [emerg] SSL_CTX_use_PrivateKey("/etc/nginx/ssl/example.com.key") failed (SSL: error:0A080006:SSL routines::EVP lib)
Usually a stale key left over from a renewal that replaced only the certificate. Re-run the diff public-key comparison above and redeploy the matching pair.
5. The file is not a certificate
nginx: [emerg] PEM_read_bio_X509_AUX() failed (SSL: error:0480006C:PEM routines::no start line:Expecting: TRUSTED CERTIFICATE)
Common when ssl_certificate and ssl_certificate_key paths were swapped, or when a DER .cer was dropped in. Convert with openssl x509 -inform DER -in cert.cer -out cert.pem.
6. Deprecation warning that often accompanies the failure
nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead
The warning alone does not stop nginx, but legacy configs that use ssl on; without a certificate trigger the headline [emerg] right after it. Replace with listen 443 ssl;.
7. Config test passes, HTTPS still fails
SSL_do_handshake() failed (SSL: error:0A00006C:SSL routines::bad key share) while SSL handshaking
On variable-based certificate paths this means the resolved path is wrong for that SNI name. Verify the naming scheme and that each file exists, since startup validation was skipped.
Validate, reload, and confirm from the outside
sudo nginx -t && sudo systemctl reload nginx
Use reload, not restart — reload is a graceful config swap and keeps existing connections alive. Then verify the served chain rather than trusting the local files:
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates
curl -sSI https://example.com | head -1
If the reload output shows nginx: [emerg] while nginx -t passed earlier, you edited the file after testing. Re-test, then reload.
FAQ
Why does the error say listen ... ssl with literal dots?
Nginx prints the directive name, not the resolved address. The file:line suffix is the actionable part; find the block there.
Can I define ssl_certificate once in the http block?
Yes — the directive is valid in http and server contexts, and server blocks inherit it. It silences the error for every SSL listener at once, but it is a poor default: every vhost then serves the same certificate. Define per server unless you genuinely have one wildcard cert.
Do I need separate server blocks for port 80 and 443?
Not strictly — one block can hold both listen 80; and listen 443 ssl; — but a dedicated port-80 block with return 301 https://$host$request_uri; is cleaner and avoids accidentally serving plaintext content.
Can several server_name values share one certificate?
Yes. List them in one server_name line and use a certificate with matching SANs, or a wildcard. The certificate does not need one entry per name.
Does the order of ssl_certificate and ssl_certificate_key matter?
No. What matters is the order inside the certificate file: leaf first, then intermediates. A reversed chain loads fine but breaks some clients and strict validators.
Where should the files live?/etc/nginx/ssl/ or /etc/pki/tls/ are both fine. What matters is a consistent SELinux label, an absolute path in the config, and a renewal hook that reloads nginx after certbot rewrites the files.
I terminate TLS at a load balancer — do I still need a certificate?
Only if nginx itself has a listen ... ssl block. If the balancer speaks plain HTTP to the origin, remove the ssl flag from the listen directive and the error disappears — but then origin traffic is unencrypted.
How do I fix this inside the official Docker image?
Mount the certificate directory into /etc/nginx/ssl, keep the config in /etc/nginx/conf.d/*.conf, and make sure the mounted files are readable by the nginx user inside the container. Then docker exec <container> nginx -t before reloading.