在 Debian 上查看 Nginx 的 SSL/TLS 状态,可以从配置是否启用、证书是否有效、运行时是否监听 HTTPS、以及实际握手情况几个层面来检查。下面按常用方法说明:
sudo nginx -T
重点看是否有:
listen 443 ssl;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
ls /etc/nginx/sites-enabled/
sudo cat /etc/nginx/sites-enabled/default
sudo ss -tulnp | grep :443
或
sudo netstat -tulnp | grep :443
有输出说明 Nginx 已在监听 HTTPS。
echo | openssl s_client -connect yourdomain.com:443 2>/dev/null | openssl x509 -noout -dates -subject
示例输出:
notBefore=May 1 00:00:00 2024 GMT
notAfter=May 1 23:59:59 2025 GMT
subject= /CN=yourdomain.com
openssl x509 -in /etc/ssl/certs/yourcert.pem -noout -dates
sudo nginx -t
输出应类似于:
nginx: configuration file /etc/nginx/nginx.conf test is successful
curl -I https://yourdomain.com
curl -v https://yourdomain.com
sudo tail -f /var/log/nginx/error.log
常见 SSL 错误:
SSL_CTX_use_PrivateKey_file → 证书/私钥不匹配cannot load certificate → 路径错误或权限不足nmap --script ssl-enum-ciphers -p 443 yourdomain.com
| 目的 | 命令 |
|---|---|
| 查看配置 | nginx -T |
| 检查端口 | `ss -tulnp |
| 检查证书 | openssl s_client -connect domain:443 |
| 测试配置 | nginx -t |
| 查看日志 | tail /var/log/nginx/error.log |
如果你愿意,可以告诉我:
我可以给你更精确的检查命令。