什么是Let’s Encrypt
Let’s Encrypt 是一家免费、开放、自动化的证书颁发机构(CA),为公众的利益而运行。它是一项由 Internet Security Research Group(ISRG)提供的服务。我们以尽可能对用户友好的方式免费提供为网站启用 HTTPS(SSL/TLS)所需的数字证书。这是因为我们想要创建一个更安全,更尊重隐私的 Web 环境。
安装certbot
安装snapd,参考:snapcraft.io
更新snapd为最新版本
1
sudo snap install core; sudo snap refresh core
删除之前可能安装的历史版本
1
2
3
4
5
6
7
8# ubuntu
sudo apt-get remove certbot
# centos 8
sudo dnf remove certbot
# centos 7
sudo yum remove certbot安装snapd
1
2
3sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot安装snapd阿里云dns插件
1
2
3
4
5sudo snap install certbot-dns-aliyun
sudo snap set certbot trust-plugin-with-root=ok
sudo snap connect certbot:plugin certbot-dns-aliyun
# 检查是否安装成功
certbot plugins
获取证书(不使用阿里dns插件)
获取并安装证书
1
sudo certbot --nginx
仅获取证书(需要手动修改配置以生效)
1
sudo certbot certonly --nginx
测试自动续订
1
sudo certbot renew --dry-run
获取证书(使用阿里DNS插件,网站使用非80端口,或者需要泛域名证书时必须使用DNS进行验证)
创建凭据文件(credentials.ini)
1
2certbot_dns_aliyun:dns_aliyun_access_key = 12345678
certbot_dns_aliyun:dns_aliyun_access_key_secret = 1234567890abcdef1234567890abcdef设置凭据文件权限
1
chmod 600 /path/to/credentials.ini
获取证书
1
2
3
4certbot certonly -a certbot-dns-aliyun:dns-aliyun \
--certbot-dns-aliyun:dns-aliyun-credentials /path/to/credentials.ini \
-d example.com \
-d "*.example.com"测试自动续订
1
sudo certbot renew --dry-run
(完)