SSL/TLS 证书申请与自动续期(Let's Encrypt) Print

  • 19

Let's Encrypt 提供免费的 SSL/TLS 证书,配合 Certbot 工具可实现自动申请和续期。

安装 Certbot

# Nginx 环境
sudo apt install certbot python3-certbot-nginx

# Apache 环境
sudo apt install certbot python3-certbot-apache

申请证书

# Nginx
sudo certbot --nginx -d example.com -d www.example.com

# Apache
sudo certbot --apache -d example.com -d www.example.com

# 仅获取证书(手动配置)
sudo certbot certonly --nginx -d example.com

证书文件位置

/etc/letsencrypt/live/example.com/fullchain.pem      # 证书文件
/etc/letsencrypt/live/example.com/privkey.pem        # 私钥文件

自动续期

# 测试续期
sudo certbot renew --dry-run

# Certbot 会自动添加 systemd 定时器
sudo systemctl list-timers | grep certbot

Nginx SSL 配置示例

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    # ... 其他配置
}

Was this answer helpful?

« Back