最新版同ECS下多域名Certbot申请通配符证书(2025年11月)
安装阿里云CLI
1
| /bin/bash -c "$(curl -fsSL https://aliyuncli.alicdn.com/install.sh)"
|
安装 certbot-dns-aliyun 插件
1 2 3 4 5
| wget https://cdn.jsdelivr.net/gh/justjavac/certbot-dns-aliyun@main/alidns.sh sudo cp alidns.sh /usr/local/bin sudo chmod +x /usr/local/bin/alidns.sh sudo ln -s /usr/local/bin/alidns.sh /usr/local/bin/alidns rm alidns.sh
|
配置参数
去阿里云控制台,RAM 访问控制 –> 身份管理 –> 用户。
创建用户,为用户分配AliyunDNSFullAccess权限。创建AccessKey。
以下方法二选一:
(一)执行命令,根据提示一步步填写
(二)手工修改配置文件 ~/.aliyun/config.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| { "current": "AkProfile", "profiles": [ { "name": "default", "mode": "", "output_format": "json", "language": "en" }, { "name": "AkProfile", "mode": "AK", "access_key_id": "your_access_key_id", "access_key_secret": "your_access_key_secret", "region_id": "cn-shenzhen", "output_format": "json", "language": "en", "site": "china" } ], "meta_path": "" }
|
测试脚本
1
| certbot certonly -d "*.harrison.wang" -d "harrison.wang" -d "*.neige.ren" -d "neige.ren" -d "*.wefuxi.com" -d "wefuxi.com" --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --dry-run
|
正式申请(去掉–dry-run)
1
| certbot certonly -d "*.harrison.wang" -d "harrison.wang" -d "*.neige.ren" -d "neige.ren" -d "*.wefuxi.com" -d "wefuxi.com" --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean"
|
证书续期
1
| certbot renew --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --dry-run
|
加入crontab
1
| 0 3 * * 4 certbot renew --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --deploy-hook "nginx -s reload"
|
参考资料
https://help.aliyun.com/zh/cli/install-cli-on-linux
https://github.com/justjavac/certbot-dns-aliyun