【发布时间】:2020-01-28 21:12:07
【问题描述】:
我想达到什么目标:
我想启动一个 nginx 容器和一个 API 容器。将它们分组在同一个网络下,proxy_pass 从 nginx 到 API 容器(使用 nginx conf 文件中的 API 容器名称)。
到目前为止我做了什么:
创建了 2 个 docker-compose 文件(因为它们不相互依赖)。如果 API 容器在 nginx 之前启动,一切正常。在 API 容器未运行时启动 nginx 时出现错误。
我遇到的错误:
nginx | 2019/09/29 07:28:19 [emerg] 1#1: host not found in upstream "api_server" in /etc/nginx/conf.d/default.conf:8
nginx | nginx: [emerg] host not found in upstream "api_server" in /etc/nginx/conf.d/default.conf:8
nginx exited with code 1
另一个问题是当 API 容器由于某种原因崩溃并重新启动时,nginx 也需要重新启动才能恢复工作。
目前的解决方法:
在 nginx 之前启动 API 容器。
我的(部分)nginx conf 文件是:
location /api_server {
proxy_pass http://api_server:2300;
}
有什么想法吗?
【问题讨论】: