我的应用程序有一个Nginx容器。这就是docker-compose中定义的服务。
nginx:
image: nginx:latest
restart: always
volumes:
- ./nginx/:/etc/nginx/
ports:
- 80:80
- 443:443卷nginx目录包含配置文件和certs文件夹。
在部署应用程序的主机中,使用以下命令手动生成TLS证书:
certbot certonly --manual --manual-public-ip-logging-ok --preferred-challenges dns -d my.app.com并且存在从实际letsEncrypt证书位置到此主机卷位置的符号链接。
/myapp/nginx/certs# ll
lrwxrwxrwx 1 root root 55 Mar 12 09:47 fullchain.pem -> /etc/letsencrypt/live/my.app.com/fullchain.pem
lrwxrwxrwx 1 root root 53 Mar 12 09:48 privkey.pem -> /etc/letsencrypt/live/my.app.com/privkey.pem每次证书过期时,我都会重新生成证书。(由于证书的生成是手动的,所以我不能使用certbot更新命令进行自动续订。当我尝试这样做时,它会给出一个错误:)
Failed to renew certificate my.app.com with error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.') 因此,当重新生成时,Certbot将续订/etc/letsencrypt/live/my.app.com/目录中的证书)。在那之后,我必须重新启动nginx容器来获取新的证书。
有没有一种方法可以自动做到这一点?有没有什么钩子可以连接到certbot来做到这一点?
发布于 2021-03-15 22:11:20
以下是如何使用md5测试证书是否更改的方法:
file=/path/to/the/certificate ; \
before=$(md5sum "$file") ; \
certbot ... ; \
after=$(md5sum "$file"); \
test "$before" = "$after" || docker exec ...这里发生了什么:
序列将当前文件的校验和保存到一个名为before.
after中)比较两个字符串,如果它们不匹配,此命令退出,状态码为1。如果它们确实匹配,则退出代码为0.
||执行它之后的任何内容,如果上一个命令退出时不是0,则退出。在这种情况下,当校验和不匹配时。https://stackoverflow.com/questions/66638205
复制相似问题