服务器:
我使用 Nginx 作为我的服务器的入口代理。Nginx 在 Docker 容器中运行。
docker-compose.yml:
nginx_ingress:
image: nginx:latest
ports:
- "80:80"
- "443:443"
networks:
front-tier: {}
back-tier:
ipv4_address: 172.28.1.1
restart: always
volumes:
- /var/lib/my-server/config/nginx_ingress:/etc/nginx/conf.d
- /var/lib/my-server/data/certbot/conf:/etc/letsencrypt
- /var/lib/my-server/data/certbot/www:/var/www/certbot
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
由于我使用另一个容器管理多个证书,因此我希望 Nginx 每 6 小时正常重新加载一次配置。
我的想法是,我可以用另一个容器独立管理我的所有证书。我不想在我的主机上运行任何东西(没有 cronjob),也不想将我的 nginx-proxy-container 与我的证书容器结合起来。我希望拼图的每一部分都能独立运行。(我从这个教程中得到了这个想法:https://pentacent.medium.com/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71)
问题:
有时代理(nginx)会停止工作。但 Docker 容器本身仍在运行。
日志显示以下内容:
...
2021/10/25 05:51:42 [notice] 1#1: signal 3 (SIGQUIT) received, shutting down
2021/10/25 05:51:42 [notice] 12#12: gracefully shutting down
2021/10/25 05:51:42 [notice] 12#12: exiting
2021/10/25 05:51:42 [notice] 13#13: gracefully shutting down
2021/10/25 05:51:42 [notice] 12#12: exit
2021/10/25 05:51:42 [notice] 13#13: exiting
2021/10/25 05:51:42 [notice] 13#13: exit
2021/10/25 05:51:42 [notice] 1#1: signal 17 (SIGCHLD) received from 12
2021/10/25 05:51:42 [notice] 1#1: worker process 12 exited with code 0
2021/10/25 05:51:42 [notice] 1#1: worker process 13 exited with code 0
2021/10/25 05:51:42 [notice] 1#1: exit
2021/10/25 05:51:44 [notice] 1#1: using the "epoll" event method
2021/10/25 05:51:44 [notice] 1#1: nginx/1.21.3
2021/10/25 05:51:44 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
2021/10/25 05:51:44 [notice] 1#1: OS: Linux 5.4.0-86-generic
2021/10/25 05:51:44 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/10/25 05:51:44 [notice] 1#1: start worker processes
2021/10/25 05:51:44 [notice] 1#1: start worker process 9
2021/10/25 05:51:44 [notice] 1#1: start worker process 10
和有时我的意思是有时。到目前为止我还没找出任何规律。一开始我以为 Nginx 每 6 小时关闭一次,原因是command
。但似乎情况并非如此。我将睡眠时间减少到 2 分钟,Nginx 继续正常运行了几个小时。然后我再次将睡眠时间设置为 6 小时,6 小时后 Nginx 停止工作(参见上面的日志)。我重新启动了 Docker 容器,从那时起 Nginx 就开始运行(现在已经过去了 24 多个小时)。正如您在以下日志中看到的那样,在大多数情况下,Nginx 重新加载工作正常:
...
2021/10/25 11:51:44 [notice] 19#19: signal process started
2021/10/25 11:51:44 [notice] 1#1: signal 1 (SIGHUP) received from 19, reconfiguring
2021/10/25 11:51:44 [notice] 1#1: reconfiguring
2021/10/25 11:51:44 [notice] 1#1: using the "epoll" event method
2021/10/25 11:51:44 [notice] 1#1: start worker processes
2021/10/25 11:51:44 [notice] 1#1: start worker process 21
2021/10/25 11:51:44 [notice] 1#1: start worker process 22
2021/10/25 11:51:44 [notice] 10#10: gracefully shutting down
2021/10/25 11:51:44 [notice] 9#9: gracefully shutting down
2021/10/25 11:51:44 [notice] 10#10: exiting
2021/10/25 11:51:44 [notice] 9#9: exiting
2021/10/25 11:51:44 [notice] 9#9: exit
2021/10/25 11:51:44 [notice] 10#10: exit
2021/10/25 11:51:44 [notice] 1#1: signal 17 (SIGCHLD) received from 10
2021/10/25 11:51:44 [notice] 1#1: worker process 9 exited with code 0
2021/10/25 11:51:44 [notice] 1#1: worker process 10 exited with code 0
2021/10/25 11:51:44 [notice] 1#1: signal 29 (SIGIO) received
...
...
2021/10/25 17:51:44 [notice] 23#23: signal process started
2021/10/25 17:51:44 [notice] 1#1: signal 1 (SIGHUP) received from 23, reconfiguring
2021/10/25 17:51:44 [notice] 1#1: reconfiguring
2021/10/25 17:51:44 [notice] 1#1: using the "epoll" event method
2021/10/25 17:51:44 [notice] 1#1: start worker processes
2021/10/25 17:51:44 [notice] 1#1: start worker process 25
2021/10/25 17:51:44 [notice] 1#1: start worker process 26
2021/10/25 17:51:44 [notice] 22#22: gracefully shutting down
2021/10/25 17:51:44 [notice] 21#21: gracefully shutting down
2021/10/25 17:51:44 [notice] 21#21: exiting
2021/10/25 17:51:44 [notice] 22#22: exiting
2021/10/25 17:51:44 [notice] 21#21: exit
2021/10/25 17:51:44 [notice] 22#22: exit
2021/10/25 17:51:44 [notice] 1#1: signal 17 (SIGCHLD) received from 21
2021/10/25 17:51:44 [notice] 1#1: worker process 21 exited with code 0
2021/10/25 17:51:44 [notice] 1#1: signal 29 (SIGIO) received
2021/10/25 17:51:44 [notice] 1#1: signal 17 (SIGCHLD) received from 22
2021/10/25 17:51:44 [notice] 1#1: worker process 22 exited with code 0
2021/10/25 17:51:44 [notice] 1#1: signal 29 (SIGIO) received
...
我的问题:
- 我使用的有什么问题吗
command
?Nginx 停止后容器是否也应该停止?(也许是主进程出了问题?) - 为什么 Nginx 只会不定期停止?为什么不是每 6 小时一次?你看到第一条日志和第二条/第三条日志之间有什么区别吗?
- 您还有其他建议吗?关于如何让 Nginx 自行重新加载?(如上所述,我不想在主机上放置任何东西 + 如果没有必要,我不想组合 nginx 和 certbot 容器......)
感谢您的帮助!