SSL/TLS 与证书管理
证书类型
| 类型 | 验证级别 | 价格 | 适用 |
|---|---|---|---|
| DV | 域名所有权 | 免费~低 | 个人/小站 |
| OV | 组织身份 | 中等 | 企业 |
| EV | 扩展验证 | 高 | 金融/电商 |
| Wildcard | *.example.com | 中等 | 多子域名 |
Let's Encrypt 自动化
certbot 自动签发与续期
# Nginx 自动配置
certbot --nginx -d example.com -d www.example.com
# 仅签发证书(手动配置)
certbot certonly --standalone -d example.com
# 自动续期测试
certbot renew --dry-run
# Crontab 或 systemd timer 自动续期
# certbot 安装后自带 systemd timer
systemctl list-timers | grep certbot
内部 CA 证书(企业内部服务)
自建 CA 签发证书
# 创建 CA 私钥和证书
openssl genrsa -out ca.key 4096
openssl req -x509 -new -key ca.key -days 3650 -out ca.crt \
-subj "/CN=Internal CA"
# 创建服务器证书签名请求
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr \
-subj "/CN=app.internal.com"
# CA 签发
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -days 365 -out server.crt
TLS 最佳实践
| 配置项 | 推荐 |
|---|---|
| TLS 版本 | 仅 TLS 1.2 + 1.3 |
| 加密套件 | ECDHE + AES-GCM |
| 密钥长度 | RSA 2048+,ECDSA 256+ |
| HSTS | max-age=31536000; includeSubDomains |
| OCSP Stapling | 开启 |
常见面试问题
Q1: 证书过期怎么应急处理?
答案:
- 临时:手动
certbot renew或certbot certonly - 验证:
openssl s_client -connect example.com:443查看证书有效期 - 预防:证书到期前 30 天告警(Prometheus blackbox_exporter 的
probe_ssl_earliest_cert_expiry) - 自动化:所有证书通过 cert-manager(K8s)或 certbot timer 自动续期