我正在尝试使用 Ansible 在服务器上自动设置 certbot + nginx。
第一次运行时,还没有 letsencrypt 证书。但是,我按如下方式创建了 nginx conf,引用了 将 由 certbot 创建的 SSL/cert 目录
server {
listen 443 ssl;
server_name example.co;
# ...
# SSL
ssl_certificate /etc/letsencrypt/live/example.co/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.co/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = example.co) {
return 301 https://$host$request_uri;
}
listen 80;
server_name example.co;
return 404;
}
然后在 ansible play 中,我使用 --nginx
插件运行 certbot-auto
,但我收到错误
> /usr/local/bin/certbot-auto certonly --nginx -n --agree-tos --text -d example.co --email admin@example.co
Error while running nginx -c /etc/nginx/nginx.conf -t.
nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/example.co/fullchain.pem"
似乎 certbot 在继续之前首先检查 nginx conf(这是有道理的)但是 conf 验证失败,因为它引用了不存在的目录。此外,--nginx
插件(或至少一些其他插件)是必需的,所以我不能将其关闭。
所以我处于一种先有鸡还是先有蛋的情况,因为 -
我无法在运行 certbot 之前创建 nginx conf,因为 certbot 尝试验证 nginx conf,但失败了,因为它引用了不存在的目录
我无法在创建 nginx conf 之前运行 certbot,因为 certbot 使用站点的 conf 来要求新证书
我能看到的唯一选择是
- 创建 nginx conf 没有
#SSL
行 - 运行 certbot 获取新证书
- 更新 nginx conf 文件以添加到
#SSL
行
这感觉很乱,但不确定是否有其他方法?
运行它的正确顺序是什么?
谢谢!
最佳答案
.conf 文件肯定需要在运行 certbot 之前存在。然后,Certbot 本身会将证书的路径写入文件,因此不需要第 3 步。
关于ssl - 哪个先出现 - 创建 nginx 站点 `.conf` 文件或运行 `certbot-auto certonly`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58295060/