【问题标题】:nginx: [emerg] host not found in upstream "api:5000" in /etc/nginx/conf.d/default.confnginx:在 /etc/nginx/conf.d/default.conf 的上游“api:5000”中找不到 [emerg] 主机
【发布时间】:2020-11-08 18:33:39
【问题描述】:

我已经搜索了几个小时,但找不到根本问题原因。这是我的 docker-compose.yml 文件,您可以在下面看到:

version: "3"
services:
   postgres:
     image: "postgres:latest"
     environment:
      - POSTGRES_PASSWORD=postgres_password
   redis:
     image: "redis:latest"
   nginx:
     restart: always
     build:
      dockerfile: Dockerfile
      context: ./nginx
     ports:
      - '3666:80'
     depends_on:
      - api
      - client
   api:
     build:
      dockerfile: Dockerfile.dev
      context: ./server
     volumes:
      - /app/node_modules
      - ./server:/app
     environment:
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - PGUSER=postgres
      - PGHOST=postgres
      - PGDATABASE=postgres
      - PGPASSWORD=postgres_password
      - PGPORT=5432
   client:
     stdin_open: true
     build:
      dockerfile: Dockerfile.dev
      context: ./client
     volumes:
      - /app/node_modules
      - ./client:/app
   worker:
     build:
      dockerfile: Dockerfile.dev
      context: ./worker
     volumes:
      - /app/node_modules
      - ./worker:/app

这是我的 nginx/default.conf

upstream client {
        server client:3000;
}

upstream api {
        server api:5000;
}

server {
        listen 80;

        location / {
                proxy_pass http://client;
        }

        location /api {
                rewrite /api/(.*) /$1 break;
                proxy_pass http://api
        }
}

当我尝试时: #docker-compose up --build
过程中出现此错误:

nginx_1 | nginx:在 /etc/nginx/conf.d/default.conf:6 的上游“api:5000”中找不到 [emerg] 主机

【问题讨论】:

  • is api 服务器可通过端口5000 访问?
  • @Adiii 是的,我在代码中控制:app.listen(5000, (err) => { console.log('Listening');

标签: docker nginx docker-compose dockerfile


【解决方案1】:

请检查你的 docker-compose 文件,你必须在 services 下设置 api

【讨论】:

猜你喜欢
  • 2020-11-09
  • 1970-01-01
  • 2016-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-22
  • 2021-06-14
  • 2018-08-15
相关资源
最近更新 更多