方便的对运行在cloudflare上的域名进行certbot-dns挑战.
npm i -g @lsby/cloudflare-certbot-dns-hook
首先您需要保证您的dns解析记录里存在您设置的子域名解析.
例如, 如果您的域名是aaa.com
, 您想为bbb.aaa.com
这个子域设置ssl证书, 您就必须先手动设置好bbb.aaa.com
的解析记录.
接下来安装certbot.
接下来创建两个文件, windows和linux略有不同.
- 文件后缀名不同, windows是
.cmd
或.bat
, linux是.sh
. - 设置环境变量的写法不同, windows是
set
, linux是export
.
下面的示例使用windows的写法:
auth.cmd:
set CLOUDFLARE_API_TOKEN=<cloudflare的token>
set CLOUDFLARE_ZONE_ID=<cloudflare域名的区域id>
lsby-cloudflare-certbot-dns-hook-auth
cleanup.cmd:
set CLOUDFLARE_API_TOKEN=<cloudflare的token>
set CLOUDFLARE_ZONE_ID=<cloudflare域名的区域id>
lsby-cloudflare-certbot-dns-hook-cleanup
最后执行命令:
certbot certonly --manual --non-interactive --preferred-challenges=dns --manual-auth-hook <auth文件路径> --manual-cleanup-hook <cleanup文件路径> --agree-tos -m <邮箱> -d <完整子域名>
- 执行后会卡住很久, 是正常的, 因为要等待dns传播. 现在设置的是等待一分钟.
- 续期时重新执行以上命令即可.