什么是Let’s Encrypt

Let’s Encrypt 是一家免费、开放、自动化的证书颁发机构(CA),为公众的利益而运行。它是一项由 Internet Security Research Group(ISRG)提供的服务。我们以尽可能对用户友好的方式免费提供为网站启用 HTTPS(SSL/TLS)所需的数字证书。这是因为我们想要创建一个更安全,更尊重隐私的 Web 环境。

安装certbot

  1. 安装snapd,参考:snapcraft.io

  2. 更新snapd为最新版本

     sudo snap install core; sudo snap refresh core
    
  3. 删除之前可能安装的历史版本

     # ubuntu
     sudo apt-get remove certbot
    
     # centos 8
     sudo dnf remove certbot
    
     # centos 7
     sudo yum remove certbot
    
  4. 安装snapd

     sudo snap install --classic certbot
    
     sudo ln -s /snap/bin/certbot /usr/bin/certbot
    
  5. 安装snapd阿里云dns插件

     sudo 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
    
  2. 仅获取证书(需要手动修改配置以生效)

     sudo certbot certonly --nginx
    
  3. 测试自动续订

     sudo certbot renew --dry-run
    

获取证书(使用阿里DNS插件,网站使用非80端口,或者需要泛域名证书时必须使用DNS进行验证)

  1. 创建凭据文件(credentials.ini)

     dns_aliyun_access_key = 12345678
     dns_aliyun_access_key_secret = 1234567890abcdef1234567890abcdef
    
  2. 设置凭据文件权限

     chmod 600 /path/to/credentials.ini
    
  3. 获取证书

     certbot certonly --authenticator dns-aliyun \
     --dns-aliyun-credentials /path/to/credentials.ini \
     -d example.com \
     -d "*.example.com"
    
  4. 测试自动续订

     sudo certbot renew --dry-run
    

(完)

文章参考: certbot-dns-aliyun certbot.eff.org 富多多