在 Debian 上验证 Nginx 的 SSL 配置是否正常工作,可以从本地配置检查、证书有效性、端口监听、外部访问、协议与安全性几个方面来做。下面按实用步骤说明。
sudo nginx -t
正常输出应类似:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl reload nginx
sudo ss -tulnp | grep nginx
或
sudo netstat -tulnp | grep nginx
应看到:
LISTEN 0 128 0.0.0.0:443
LISTEN 0 128 :::443
常见路径(以 Let’s Encrypt 为例):
/etc/letsencrypt/live/example.com/fullchain.pem
/etc/letsencrypt/live/example.com/privkey.pem
Nginx 配置中应有:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
检查证书有效期:
sudo openssl x509 -in /etc/letsencrypt/live/example.com/fullchain.pem -noout -dates
curl -I https://localhost
或
curl -v https://yourdomain.com
无证书错误即基本正常。
curl -k https://服务器IP
curl -I https://yourdomain.com
或使用浏览器访问:
https://yourdomain.com
查看:
openssl s_client -connect yourdomain.com:443
可检查:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
}
HTTP 跳转 HTTPS:
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
| 问题 | 可能原因 |
|---|---|
| 浏览器提示不安全 | 证书未签发或域名不匹配 |
| 无法访问 443 | 防火墙未放行 |
| nginx -t 报错 | 证书路径错误或权限不足 |
| 证书即将过期 | 未配置自动续期 |
如果你愿意,可以贴出:
server 配置我可以帮你具体分析和优化配置。