跳到正文
English

从零搭建个人服务器(03):Nginx 与 HTTPS

Let's Encrypt 证书、TLS 1.3、HSTS、OCSP Stapling 与安全响应头的完整实践清单。

DigitalScope1 min

nginxhttpssecurity

☰ 本文目录(3 节)

让 Nginx 把 HTTP 流量安全地交还给应用,是服务器系列的第三步。这一篇覆盖证书、协议与安全头三件事,目标是在 SSL Labs 拿到 A+。

证书:Let's Encrypt + Certbot#

bash · certbot
sudo apt install certbot python3-certbot-nginxsudo certbot --nginx -d blog.example.comsudo certbot renew --dry-run   # 验证自动续期

TLS 参数#

只保留现代协议与套件:

nginx · tls.conf
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-Securitymax-age=63072000强制 HTTPS
X-Content-Type-Optionsnosniff禁止 MIME 嗅探
Referrer-Policystrict-origin-when-cross-origin控制引用来源
Content-Security-Policydefault-src 'self'内容安全策略