在 Debian 上测试 Nginx 的 SSL/TLS 配置,通常分为 配置语法检查、Nginx 重载测试、端口与证书验证、安全配置评估 几个步骤。下面按实用流程说明。
sudo nginx -t
正常输出示例:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
如果有错误,会根据提示修改对应文件(通常在 /etc/nginx/sites-enabled/ 或 /etc/nginx/conf.d/)。
sudo systemctl reload nginx
或:
sudo service nginx reload
sudo ss -tulnp | grep nginx
或:
sudo netstat -tulnp | grep nginx
应能看到:
LISTEN 0 128 0.0.0.0:443
LISTEN 0 128 0.0.0.0:80
echo | openssl s_client -connect localhost:443 2>/dev/null | openssl x509 -noout -dates -subject
重点看:
echo | openssl s_client -connect yourdomain.com:443 -servername yourdomain.com
curl -I https://yourdomain.com
强制验证证书:
curl -vI https://yourdomain.com
https://yourdomain.com可检测:
git clone https://github.com/drwetter/testssl.sh.git
cd testssl.sh
./testssl.sh https://yourdomain.com
一个较安全的 Debian Nginx SSL 配置示例:
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /etc/ssl/certs/yourdomain.crt;
ssl_certificate_key /etc/ssl/private/yourdomain.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /var/www/html;
index index.html;
}
}
并建议:
server {
listen 80;
server_name yourdomain.com;
return 301 https://$host$request_uri;
}
| 问题 | 可能原因 |
|---|---|
nginx -t 报错 |
路径错误或证书权限问题 |
| 浏览器不安全 | 证书域名不匹配或自签名 |
| 443 无法访问 | 防火墙 / 云安全组未开放 |
| TLS 太弱 | 启用了 TLS1.0/1.1 |
如果你愿意,可以:
我可以直接帮你检查并优化配置。