gpt4 book ai didi

nginx - Docker 网络 - nginx : [emerg] host not found in upstream

转载 作者:IT老高 更新时间:2023-10-28 12:33:54 29 4
gpt4 key购买 nike

我最近开始迁移到 Docker 1.9 和 Docker-Compose 1.5 的网络功能以替换使用链接。

到目前为止,通过 docker-compose 连接到位于一组不同服务器中的我的 php5-fpm fastcgi 服务器的 nginx 没有任何问题。新虽然当我运行 docker-compose --x-networking up 我的 php-fpm、mongo 和 nginx 容器启动时,但是 nginx 立即退出 [emerg] 1#1: host在/etc/nginx/conf.d/default.conf:16 的上游“waapi_php_1”中找不到

但是,如果我在 php 和 mongo 容器正在运行(nginx 退出)时再次运行 docker-compose 命令,则 nginx 将从那时起启动并正常工作。

这是我的 docker-compose.yml 文件:

nginx:
image: nginx
ports:
- "42080:80"
volumes:
- ./config/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro

php:
build: config/docker/php
ports:
- "42022:22"
volumes:
- .:/var/www/html
env_file: config/docker/php/.env.development

mongo:
image: mongo
ports:
- "42017:27017"
volumes:
- /var/mongodata/wa-api:/data/db
command: --smallfiles

这是我用于 nginx 的 default.conf:

server {
listen 80;

root /var/www/test;

error_log /dev/stdout debug;
access_log /dev/stdout;

location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}

location ~ ^/.+\.php(/|$) {
# Referencing the php service host (Docker)
fastcgi_pass waapi_php_1:9000;

fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;

# We must reference the document_root of the external server ourselves here.
fastcgi_param SCRIPT_FILENAME /var/www/html/public$fastcgi_script_name;

fastcgi_param HTTPS off;
}
}

如何让 nginx 只使用一个 docker-compose 调用?

最佳答案

这可以通过提到的 depends_on 指令解决,因为它现在已经实现(2016 年):

version: '2'
services:
nginx:
image: nginx
ports:
- "42080:80"
volumes:
- ./config/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php

php:
build: config/docker/php
ports:
- "42022:22"
volumes:
- .:/var/www/html
env_file: config/docker/php/.env.development
depends_on:
- mongo

mongo:
image: mongo
ports:
- "42017:27017"
volumes:
- /var/mongodata/wa-api:/data/db
command: --smallfiles

成功测试:

$ docker-compose version
docker-compose version 1.8.0, build f3628c7

documentation 中查找更多详细信息.

还有一篇非常有趣的文章专门讨论这个话题:Controlling startup order in Compose

关于nginx - Docker 网络 - nginx : [emerg] host not found in upstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33639138/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com