从零搭建个人服务器(03):Nginx 与 HTTPS
Let's Encrypt 证书、TLS 1.3、HSTS、OCSP Stapling 与安全响应头的完整实践清单。
☰ 本文目录(3 节)
让 Nginx 把 HTTP 流量安全地交还给应用,是服务器系列的第三步。这一篇覆盖证书、协议与安全头三件事,目标是在 SSL Labs 拿到 A+。
证书:Let's Encrypt + Certbot#
sudo apt install certbot python3-certbot-nginxsudo certbot --nginx -d blog.example.comsudo certbot renew --dry-run # 验证自动续期TLS 参数#
只保留现代协议与套件:
ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;ssl_prefer_server_ciphers off;ssl_stapling on;ssl_stapling_verify on;安全响应头#
| Header | 值 | 作用 |
|---|---|---|
| Strict-Transport-Security | max-age=63072000 | 强制 HTTPS |
| X-Content-Type-Options | nosniff | 禁止 MIME 嗅探 |
| Referrer-Policy | strict-origin-when-cross-origin | 控制引用来源 |
| Content-Security-Policy | default-src 'self' | 内容安全策略 |