跳到主要内容

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+
HSTSmax-age=31536000; includeSubDomains
OCSP Stapling开启

常见面试问题

Q1: 证书过期怎么应急处理?

答案

  1. 临时:手动 certbot renewcertbot certonly
  2. 验证openssl s_client -connect example.com:443 查看证书有效期
  3. 预防:证书到期前 30 天告警(Prometheus blackbox_exporter 的 probe_ssl_earliest_cert_expiry
  4. 自动化:所有证书通过 cert-manager(K8s)或 certbot timer 自动续期

相关链接