YEGUO

let's Encrypt

|
|
2 min read

我的环境是Debian11、Nginx,选择自己的环境

https://certbot.eff.org/instructions

一、安装snapd

可以在官方找到各个操作系统安装教程

https://snapcraft.io/docs/installing-snapd

我这里使用的Debian

sudo apt update
sudo apt install snapd

测试是否安装成功

sudo snap install hello-world
# hello-world 6.3 from Canonical✓ installed
$ hello-world
# Hello World!

二、安装Certbot

sudo snap install --classic certbot

确保certbot命令可以运行

sudo ln -s /snap/bin/certbot /usr/bin/certbot

三、直接生成证书

sudo certbot certonly --standalone -d example.com -d www.example.com

四、DNS验证方式

1、配置snap插件信任

sudo snap set certbot trust-plugin-with-root=ok

2、安装DNS插件

Certbot 提供了一系列 DNS 插件,适用于不同的 DNS 提供商。

  • Cloudflare 插件

    sudo snap install certbot-dns-cloudflare
  • AWS 插件:

    sudo snap install certbot-dns-route53
  • DigitalOcean 插件:

    sudo snap install certbot-dns-route53

3、配置 DNS API 凭证

我使用的是Cloudflare的DNS

mkdir -p ~/.secrets/certbot
echo "dns_cloudflare_email = your-email@example.com" >> ~/.secrets/certbot/cloudflare.ini
echo "dns_cloudflare_api_key = your-global-api-key" >> ~/.secrets/certbot/cloudflare.ini
chmod 600 ~/.secrets/certbot/cloudflare.ini.
or
mkdir -p ~/.secrets/certbot
echo "dns_cloudflare_api_token = your-zone-token" >> ~/.secrets/certbot/cloudflare.ini

注意:如果使用的是区域Token的权限的话,不需要设置dns_cloudflare_email和dns_cloudflare_api_key,只需要设置dns_cloudflare_api_token就行了

4、生成泛域名证书

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

这里包含了根域名,这种方式生成后需要手动配置

成功!

image-20240722120707052

生成的证书和密钥一般在/etc/letsencrypt/live/example.com目录下

五、测试自动续约

let’s encrypt 的证书一般只有三个月时效

sudo certbot renew --dry-run

image-20240722120940851

配置好证书后,登录网站查看证书

image-20240722145532497

© 2023 - 2026 YEGUO