ssl - 哪个先出现 - 创建 nginx 站点 `.conf` 文件或运行 `certbot-auto certonly`?

标签 ssl nginx ansible certbot

我正在尝试使用 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 插件(或至少一些其他插件)是必需的,所以我不能将其关闭。

所以我处于一种先有鸡还是先有蛋的情况,因为 -

  1. 我无法在运行 certbot 之前创建 nginx conf,因为 certbot 尝试验证 nginx conf,但失败了,因为它引用了不存在的目录

  2. 我无法在创建 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/

相关文章:

java - Tomcat 在 https 中编码重定向

git - Jenkins构建无法正确执行 `docker tag`命令

iphone - Appstore - 作为个人导出合规性?

html - 中等公共(public)站点的体面 HTTPs 实现是否始终是付费解决方案?

node.js - 使用来自拥有的域的 TLS 证书,并在 AWS Elastic Beanstalk 提供的 URL 上使用它

apache - Node.JS前面反向代理的优点

Nginx map 不使用我的正则表达式的参数

loops - 循环遍历子元素的子元素

字符串不匹配时的 Ansible 条件

php - 有没有办法在客户端验证 javascript 文件的完整性?