为 nginx 部署 Certbot

环境

官方文档

速查手册

如果使用其他包管理器安装了 Certbot,需要先使用对应包管理器移除 Certbot。

安装 Certbot:

sudo snap install --classic certbot

建立一个软连接,方便使用 certbot 命令:

sudo ln -s /snap/bin/certbot /usr/local/bin/certbot

申请证书:

sudo certbot certonly --nginx

验证

使用 ls 检查 /etc/letsencrypt/live/<your host name>

ls /etc/letsencrypt/live/<your host name>

期待得到:

cert.pem  chain.pem  fullchain.pem  privkey.pem  README

使用官方文档提供的命令测试:

sudo certbot renew --dry-run

期待得到:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/<your host name>.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for <your host name>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
  /etc/letsencrypt/live/<your host name>/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -