如何设置Nginx的SSL/TLS加密?
2025-04-14
3
参考资料
获取SSL证书
从CA机构购买或使用Let's Encrypt免费证书
证书通常包含:证书文件(.crt)和私钥文件(.key)
配置Nginx
在nginx.conf或站点配置文件中添加:
示例配置:
server { listen 443 ssl; server_name example.com; ssl_certificate /path/to/certificate.crt; ssl_certificate_key /path/to/private.key; # 安全协议配置 ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384'; ssl_prefer_server_ciphers on; # 其他配置... }
强制HTTPS重定向(可选)
server { listen 80; server_name example.com; return 301 https://$host$request_uri; }
验证配置并重启
nginx -t # 测试配置 systemctl restart nginx
安全增强建议
启用HSTS头:add_header Strict-Transport-Security "max-age=63072000"
定期更新SSL证书
禁用旧版TLS协议(TLS 1.0/1.1)
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。