使用Certbot獲取配置Let's Encrypt的ssl證書
阿新 • • 發佈:2022-04-06
安裝 snap
sudo apt update sudo apt install snapd
安裝 Certbot
sudo snap install --classic certbot
連結檔案,方便使用命令
sudo ln -s /snap/bin/certbot /usr/bin/certbot
因為這裡使用的是Cloudflare解析,這裡直接安裝Cloudflare外掛,
若支援的外掛沒有的DNS服務商,請自行移步這裡檢視獲取證書的方法
https://certbot.eff.org/instructions?ws=nginx&os=debianbuster
sudo snap install certbot-dns-cloudflare
若出現以下錯誤,則執行根據提示snap set certbot trust-plugin-with-root=ok即可
error: cannot perform the following tasks: - Run hook prepare-plug-plugin of snap "certbot" (run hook "prepare-plug-plugin": ----- Only connect this interface if you trust the plugin author to have root on the system. Run `snap set certbot trust-plugin-with-root=ok` to acknowledge this and then run this command again to perform the connection. If that doesn't work, you may need to remove all certbot-dns-* plugins from the system, then try installing the certbot snap again. -----)
配置外掛所需的Cloudflare帳戶裡的API Key,建立一個檔案(假設放在/etc/cloudflare.ini),內容如下
dns_cloudflare_api_token = your api key
獲取證書
certbot certonly \ --dns-cloudflare \ --dns-cloudflare-credentials /etc/cloudflare.ini \ -d domainname.com \ -d *.domainname.com
如果沒有意外,將返回獲取成功的資訊,自行檢視證書存放的位置,在去配置Nginx即可