The Nginx worker process failed to establish a secure TLS connection with a peer because the peer unexpectedly terminated the handshake.
This usually happens because the peer doesn’t understand or doesn’t support the TLS cipher suites or protocol versions Nginx is offering, or because a firewall is interfering with the TLS negotiation.
Common Causes and Fixes
-
Client TLS Version Mismatch: The client is trying to connect using an older TLS version (like TLSv1 or TLSv1.1) that Nginx has disabled for security reasons.
- Diagnosis: Check your Nginx
ssl_protocolsdirective. If it only listsTLSv1.2 TLSv1.3, clients on older versions will fail. - Fix: For maximum compatibility, you might temporarily add
TLSv1.1back, though this is discouraged for security. Edit your Nginx configuration (e.g.,/etc/nginx/nginx.confor a site-specific file inconf.d/orsites-available/):
Then reload Nginx:ssl_protocols TLSv1.2 TLSv1.3 TLSv1.1;sudo systemctl reload nginx. - Why it works: This explicitly allows Nginx to negotiate using TLSv1.1 if the client only supports it.
- Diagnosis: Check your Nginx
-
Client Cipher Suite Mismatch: The client does not support any of the cipher suites Nginx is configured to use.
- Diagnosis: Examine your
ssl_ciphersdirective. Modern Nginx configurations often use strong, modern cipher suites. - Fix: You may need to add more compatible cipher suites. A common, broader set includes:
Add this to your Nginx configuration within thessl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA';serverblock that uses SSL, and reload:sudo systemctl reload nginx. - Why it works: This expands the list of acceptable encryption algorithms, increasing the chance of finding a common one with the client.
- Diagnosis: Examine your
-
Intermediate Firewall/Proxy Interference: A network device between Nginx and the client is inspecting or modifying TLS traffic, causing the handshake to fail. This is particularly common with older, stateful firewalls.
- Diagnosis: This is harder to diagnose directly. Try accessing Nginx from a client on the same network segment as the server, bypassing any intermediate firewalls. If it works there, a firewall is the likely culprit.
- Fix: Consult your network administrator to either configure the firewall to allow the specific TLS traffic or to disable TLS inspection for this connection. There’s no Nginx configuration fix for this.
- Why it works: Removing the interfering device allows the TLS handshake to complete without modification.
-
Incorrect Certificate Chain: The client cannot validate the Nginx server’s certificate because it’s missing intermediate certificates, or the chain is malformed.
- Diagnosis: Use
openssl s_client -connect your_domain.com:443 -servername your_domain.comand check theverify return code. A code indicating an unknown certificate authority or a broken chain points to this. - Fix: Ensure your SSL certificate bundle includes the full chain. Concatenate your server certificate and all intermediate certificates into a single file, with the server certificate first, followed by the intermediates. For example, if your cert is
domain.crt, intermediates areintermediate1.crtandintermediate2.crt:
Update yourcat domain.crt intermediate1.crt intermediate2.crt > fullchain.pemssl_certificatedirective in Nginx to point tofullchain.pemand reload:sudo systemctl reload nginx. - Why it works: Providing the complete chain allows the client’s TLS library to trace the certificate back to a trusted root CA.
- Diagnosis: Use
-
Client Server Name Indication (SNI) Issue: If Nginx hosts multiple SSL sites on the same IP address, and the client doesn’t send a valid
Hostheader or SNI extension, Nginx might present the wrong certificate or fail the handshake.- Diagnosis: Check Nginx logs for messages related to SNI. The
openssl s_clientcommand (as above) will show the certificate presented. If it’s not the one expected foryour_domain.com, SNI is likely the issue. - Fix: Ensure clients are sending a valid
Hostheader and that Nginx is configured correctly for SNI. For older clients that don’t support SNI, you might need a defaultserverblock that listens on port 443 without SNI requirements and serves a generic certificate, or ensure your primaryserverblock catches all un-SNI’d requests.
Reload Nginx:server { listen 443 ssl default_server; server_name _; # Catches requests without a specific server_name or SNI ssl_certificate /etc/nginx/ssl/default.pem; ssl_certificate_key /etc/nginx/ssl/default.key; # ... other SSL settings, possibly a redirect or error page }sudo systemctl reload nginx. - Why it works: This provides a fallback certificate for clients that don’t specify a hostname via SNI, allowing the handshake to proceed.
- Diagnosis: Check Nginx logs for messages related to SNI. The
-
Outdated OpenSSL Library on Server: The Nginx server itself might be running an extremely old version of OpenSSL that has compatibility issues with modern clients or specific cipher suites.
- Diagnosis: Check your Nginx version (
nginx -v) and the OpenSSL version it’s linked against (openssl version). While Nginx might be recent, it could be compiled against an old OpenSSL. - Fix: Update Nginx and its OpenSSL dependencies to current stable versions. This typically involves using your distribution’s package manager (e.g.,
sudo apt update && sudo apt upgrade nginx opensslon Debian/Ubuntu, orsudo yum update nginx opensslon CentOS/RHEL). - Why it works: Newer OpenSSL libraries support a wider range of modern TLS features and cipher suites, improving compatibility.
- Diagnosis: Check your Nginx version (
After fixing these, the next error you’ll likely encounter is a "502 Bad Gateway" if your Nginx is acting as a reverse proxy and the upstream application server is having issues.