Debian 上 Nginx 的 SSL 失败原因非常多,下面按最常见 → 较少见的顺序帮你系统梳理,并给出排查方法。你可以对照看是哪一类。
Nginx 配置中:
ssl_certificate /etc/nginx/ssl/example.com.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
常见问题:
✅ 检查:
ls -l /etc/nginx/ssl/
nginx -t
openssl x509 -noout -modulus -in example.com.crt | openssl md5
openssl rsa -noout -modulus -in example.com.key | openssl md5
两个 md5 必须一致。
只放了 example.com.crt,没有中间证书(Intermediate CA)
✅ 正确做法(合并):
cat example.com.crt intermediate.crt > fullchain.crt
然后:
ssl_certificate /etc/nginx/ssl/fullchain.crt;
server {
listen 443 ssl;
...
}
❌ 错误示例:
listen 443;
# 没有 ssl;
nginx -V 2>&1 | grep ssl
应该看到 --with-http_ssl_module
Debian + Nginx 会直接报错:
SSL_CTX_use_PrivateKey_file failed
✅ 推荐权限:
chmod 600 /etc/nginx/ssl/*.key
chown root:root /etc/nginx/ssl/*.key
sudo -u www-data cat /etc/nginx/ssl/example.com.key
ss -tulnp | grep 443
或
ufw allow 443/tcp
date
证书是未来时间也会失败。
certbot --nginx
常见错误:
fullchain.pem 但路径错✅ 正确路径:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
nginx -t
journalctl -u nginx -xe
openssl s_client -connect example.com:443
请把以下信息发我:
nginx -t 输出/var/log/nginx/error.log)我可以直接告诉你是哪一行导致 SSL 失败。