「Certbot」- 常见问题处理、常用配置

当部署 certbot 成功后,剩下的任务就是通读官方文档,以解决各种问题:
Welcome to the Certbot documentation! — Certbot 1.15.0.dev0 documentation

博客笔记都是静态页面,用不用 HTTPS 都可以,但是大家都在用…………所以尝尝味道嘛,反正也买不起证书…………而且用这东西只是早晚的事情。

该笔记将记录:如何申请免费证书来启用 HTTPS 站点。

性能测试

http_load – multiprocessing http test client

在证书自动续期后,自动重启相关服务

User Guide — Certbot 1.15.0.dev0 documentation

参考 Renewing certificates 部分,以获得关于证书续期相关的完整说明。

在 Certbot 自动续期之后,需要重启相关服务,比如 Nginx 服务,以应用新的证书。

通过命令行:

certbot renew --deploy-hook "/path/to/deploy-hook-script"

通过配置文件:脚本保存在 /etc/letsencrypt/renewal-hooks/deploy 目录,当证书申请成功后,certbot 将执行该目录下的脚本。

执行顺序:按字母顺序排列的,并且不依赖于 Locale 域设置

针对非标准路径的 Nginx 部署

certbot run -a dns-dnspod                                  \
    --dns-dnspod-credentials /etc/letsencrypt/dnspod-credentials.ini \
    --nginx-server-root=/usr/local/nginx/conf/             \
    --nginx-ctl=/usr/local/nginx/sbin/nginx                \
    --no-redirect

–no-redirect,该参数禁用 Certbot 自动配置 80 到 443 重定向。
–nginx-server-root=/usr/local/nginx/conf/,该路径需要包含 nginx.conf 文件。
–nginx-ctl=/usr/local/nginx/sbin/nginx,该参数指定 nginx 二进制程序的路径。

certbot-dns-route53

https://snapcraft.io/install/certbot-dns-route53/ubuntu

https://certbot-dns-route53.readthedocs.io/en/stable/

snap install certbot --classic

snap set certbot trust-plugin-with-root=ok
snap install certbot-dns-route53

mkdir -pv /etc/letsencrypt/
cat > /etc/letsencrypt/route53-credentials.ini<<EOF
[default]
aws_access_key_id=xxxxxxxxxxxxxxxx
aws_secret_access_key=xxxxxxxxxxxxxxxx
EOF

chmod 600 /etc/letsencrypt/route53-credentials.ini

AWS_CONFIG_FILE=/etc/letsencrypt/route53-credentials.ini

certbot run
    --authenticator dns-route53 \
    --dns-route53-credentials /etc/letsencrypt/route53-credentials.ini

certbot certonly -a dns-dnspod \
    --dns-dnspod-credentials /etc/letsencrypt/dnspod-credentials.ini \
    -d "*.devops.example.com"

注意事项:

  • 刚方式并不强制使用 DNS 质询,如果失败,则会回退到 HTTP 质询;