certbot-dns-aliyun
解決阿里云 DNS 不能自動(dòng)為通配符證書續(xù)期的問題
原理
當(dāng)我們使用 certbot 申請(qǐng)通配符證書時(shí),需要手動(dòng)添加 TXT 記錄。每個(gè) certbot 申請(qǐng)的證書有效期為 3 個(gè)月,雖然 certbot 提供了自動(dòng)續(xù)期命令,但是當(dāng)我們把自動(dòng)續(xù)期命令配置為定時(shí)任務(wù)時(shí),我們無法手動(dòng)添加新的 TXT 記錄用于 certbot 驗(yàn)證。
好在 certbot 提供了一個(gè) hook,可以編寫一個(gè) Shell 腳本。在續(xù)期的時(shí)候讓腳本調(diào)用 DNS 服務(wù)商的 API 接口動(dòng)態(tài)添加 TXT 記錄,驗(yàn)證完成后再刪除此記錄。
安裝
-
安裝 aliyun cli 工具
wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz tar xzvf aliyun-cli-linux-latest-amd64.tgz sudo cp aliyun /usr/local/bin rm aliyun
安裝完成后需要配置憑證信息
-
安裝 certbot-dns-aliyun 插件
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
-
申請(qǐng)證書
測(cè)試是否能正確申請(qǐng):
certbot certonly -d *.example.com --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --dry-run
正式申請(qǐng)時(shí)去掉
--dry-run
參數(shù):- 單域名申請(qǐng)
certbot certonly -d *.example.com --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean"
- 多域名申請(qǐng)
certbot certonly -d '*.example.com' -d '*.example.site' -d '*.example.fun' --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean"
-
證書續(xù)期
certbot renew --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --dry-run
如果以上命令沒有錯(cuò)誤,把
--dry-run
參數(shù)去掉。 -
自動(dòng)續(xù)期
添加定時(shí)任務(wù) crontab。
crontab -e
輸入文章來源:http://www.zghlxwxcb.cn/news/detail-826490.html
1 1 */1 * * root certbot renew --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --deploy-hook "nginx -s reload"
上面腳本中的
--deploy-hook "nginx -s reload"
表示在續(xù)期成功后自動(dòng)重啟 nginx。文章來源地址http://www.zghlxwxcb.cn/news/detail-826490.html
到了這里,關(guān)于使用certbot申請(qǐng)https通配符證書【阿里云篇】的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!