GrepBoard/Manuals
605 manuals ·

Fix nginx: no ssl_certificate is defined for listen ... ssl

·Tested on nginx 1.30.6 (Docker) · OpenSSL 3.5.7 · 2026-10·Test scope ↓·5 steps

nginx says no ssl_certificate is defined for listen ... ssl when a port's default server lacks a certificate. Add one there or use ssl_reject_handshake.

output
nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/conf.d/default.conf:1

One of the server blocks with listen … ssl has no certificate (ssl_certificate). The file:line at the end is the line where that server block starts. Add the certificate to that block, or, if it is a default server meant to run without one, use ssl_reject_handshake on;. nginx will not start in this state, so the fix has to pass nginx -t before a reload.

[1] Open the server block on the reported line. For each port (address) this check starts with that port's default server. In this reproduction two server blocks share 443 and only the first one, the default server, lacks a certificate:

/etc/nginx/conf.d/default.conf
server {    listen 443 ssl;    server_name b.example.com;    root /usr/share/nginx/html;} server {    listen 443 ssl;    server_name a.example.com;    ssl_certificate     /etc/nginx/ssl/a.example.com.crt;    ssl_certificate_key /etc/nginx/ssl/a.example.com.key;    root /usr/share/nginx/html;}
console
# nginx -t
output
2026/10/27 03:46:45 [emerg] 10#10: no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/conf.d/default.conf:1nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/conf.d/default.conf:1nginx: configuration file /etc/nginx/nginx.conf test failed

:1 is the server { line of the first block. Without an explicit default_server, the first block read for a port becomes its default, so renaming files in sites-enabled can change which block fails. To check which block is the default, see duplicate default server.

[2] The reverse also holds: if the default server has a certificate, the check passes even when other blocks have none. Swap the two blocks above and nginx -t passes, but connecting as b.example.com returns the default server's certificate.

console
$ openssl s_client -connect 127.0.0.1:443 -servername b.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject
output
subject=CN=a.example.com

Browsers show that as a name mismatch warning. The error going away does not mean the job is done, so list every block on 443 and check for a certificate in one pass.

console
# nginx -T 2>/dev/null | grep -nE '^\s*(server_name|listen|ssl_certificate)\s'
output
138:    listen 443 ssl;139:    server_name a.example.com;140:    ssl_certificate     /etc/nginx/ssl/a.example.com.crt;146:    listen 443 ssl;147:    server_name b.example.com;

A block with listen … ssl and server_name but no ssl_certificate line after them (146–147) is the gap.

[3] Before changing anything, copy the current file outside conf.d (used for rollback in [5]).

console
# cp -a /etc/nginx/conf.d/default.conf /root/default.conf.bak

Add the two certificate lines to that block. If every block uses the same certificate (a wildcard, for example), put it once in the http block instead. ssl_certificate is valid in both http and server, and inner blocks inherit it.

/etc/nginx/conf.d/default.conf
server {    listen 443 ssl;    server_name b.example.com;    ssl_certificate     /etc/nginx/ssl/b.example.com.crt;    ssl_certificate_key /etc/nginx/ssl/b.example.com.key;    root /usr/share/nginx/html;}

[4] For a default server that has no certificate and turns away unknown names, use ssl_reject_handshake on; (nginx 1.19.4 and later). That block passes the check without a certificate. Because the default server now has nothing to hand out, the fallback seen in [2] disappears and every other block must have its own certificate.

Here the default server was switched to reject mode while b.example.com still had no certificate:

/etc/nginx/conf.d/default.conf
server {    listen 443 ssl default_server;    ssl_reject_handshake on;}…
console
# nginx -t
output
2026/10/27 03:46:46 [emerg] 10#10: no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/conf.d/default.conf:14nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/conf.d/default.conf:14nginx: configuration file /etc/nginx/nginx.conf test failed

Line 14 is the b.example.com block. With a certificate added there the check passes, each name gets its own certificate, and names not in the list are rejected at the handshake.

console
$ openssl s_client -connect 127.0.0.1:443 -servername b.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject$ openssl s_client -connect 127.0.0.1:443 -servername c.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject
output
subject=CN=b.example.comCould not find certificate from <stdin>…

The second line means no certificate came back for c.example.com, so openssl x509 had nothing to read.

[5] Reload once the test passes, then repeat the openssl s_client check from [2] for each name.

console
# nginx -t && systemctl reload nginx

If health checks or some clients start failing at TLS after the reload, restore the copy from [3]:

console
# cp -a /root/default.conf.bak /etc/nginx/conf.d/default.conf# nginx -t && systemctl reload nginx

If the paths are now set but you get cannot load certificate or key values mismatch, the problem is in the files themselves. Matching a certificate to its key is covered in key values mismatch.

Analyze your Nginx log in the browser ↗ — nothing is uploaded.

Check it with the Certificate (PEM · X.509) decoder tool ↗ — calculated in your browser.

#nginx#ssl#tls#default-server#sni