我正在尝试使用Ansible在服务器上自动设置certbot + nginx。
第一次运行时,尚没有letencrypt证书。但是,我按照以下方式创建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; }
然后在接下来的剧本中,我使用
certbot-auto
插件运行--nginx
,但收到错误消息
> /usr/local/bin/certbot-auto certonly --nginx -n --agree-tos --text -d example.co --email [email protected] 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来要求新证书
我唯一能看到的是
#SSL
行#SSL
行中添加这感觉很混乱,但是不确定是否还有其他方法?
执行此命令的正确顺序是什么?
谢谢!
我正在尝试使用Ansible在服务器上自动设置certbot + nginx。第一次运行时,还没有letencrypt证书。但是我按如下方式创建了nginx conf,...
。conf文件在运行certbot之前肯定需要存在。然后,Certbot自己将证书的路径写入文件中,因此步骤3不必要。