Sig*_*Sig 3 nginx docker lets-encrypt
我在 Docker 容器中运行 Nginx,需要定期重新加载其配置以获取更新的Letsecnrypt SSL 证书。
在docker-compose文件中我有以下内容
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
Run Code Online (Sandbox Code Playgroud)
据我所知,应该每 6 小时重新加载配置并重新启动 Nginx。然而,它不起作用。SSL 证书已续订,但 Nginx 未获取它。
关于如何每隔几个小时正确地重新加载 Letsencrypt SSL 证书有什么想法吗?
更新 08/08/19
根据我的理解,这个问题与我挂载到容器中的证书文件实际上是符号链接有关,而符号链接不能很好地与 Docker 配合使用。
这些涉及 while 循环的解决方案在信号处理command方面docker-composer.yml存在根本缺陷。shell脚本现在是接收关闭信号的主进程,但它不会正确转发到nginx。这会导致容器不会立即关闭docker-compose down,然后在被杀死之前会遇到默认的 10 秒超时。请参阅为什么我的服务需要 10 秒才能重新创建或停止?
这是一个将 nginx 作为主进程的解决方案:
version: '3.6'
services:
nginx:
image: nginx
volumes:
- ./99-autoreload.sh:/docker-entrypoint.d/99-autoreload.sh
# add certbot container here
Run Code Online (Sandbox Code Playgroud)
然后创建一个文件99-autoreload.sh:
#!/bin/sh
while :; do
# Optional: Instead of sleep, detect config changes and only reload if necessary.
sleep 6h
nginx -t && nginx -s reload
done &
Run Code Online (Sandbox Code Playgroud)
别忘了chmod 755 99-autoreload.sh,否则不会被执行。
更高级的设置是实际检测更改并仅在必要时重新加载。inotifywait这可以通过例如来完成。
| 归档时间: |
|
| 查看次数: |
4609 次 |
| 最近记录: |