使用certbot和cloudflare的dns-api模式自动续订ssl通配符证书

2026-08-22T23:57:00

情景需求: nginx以及hysteria需要使用证书验证

linux安装certbot

  • 系统更新

    apt -y update

  • 安装certbot

    sudo apt install certbot python3-certbot-dns-cloudflare

获取cloudflare下api_token

  • 注册cloudflare
  • api_token指令路径
    位于具体domain下侧边栏: Manage account- Account API tokens 选项

将token放入特定位置

  • 创建token目录

    mkdir -p ~/.secrets/certbot

  • 创建密钥文件

    nano ~/.secrets/certbot/cloudflare.ini

  • 放入密钥

    dns_cloudflare_api_token = YOUR_CLOUDFLARE_API_TOKEN

SSL证书申请指令

certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \
  -d example.com \
  -d "*.example.com"

验证是否续订成功

certbot renew --dry-run

  • 执行反馈会看到

    Successfully received certificate.
    Certificate is saved at: /etc/letsencrypt/live/baidu.com/fullchain.pem
    Key is saved at: /etc/letsencrypt/live/baidu.com/privkey.pem
    This certificate expires on 2026-11-20.
    These files will be updated when the certificate renews.
    Certbot has set up a scheduled task to automatically renew this certificate in the background.

以上信息会看到证书路径和下次续期日期

证书软链接

  • 一般情况,在ssl证书目录层级较深,可选择将软链接引导至使用目录
  • 读取软链接根目录

    readlink /etc/letsencrypt/live/baidu.com/fullchain.pem

  • 使用软连接引导

    ln -s remote_file local_file

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »