nginx处理端口时看不到地址,输出502 Bad Gateway

Can't see the address when nginx processes the port and outputs 502 Bad Gateway

在学习nginx的时候遇到了一个问题。我在 2 个不同的端口上有 2 个服务器。我希望在访问“http://localhost/api/v1/clients/”时返回一个包含存储在端口 8000 上的信息的页面。现在我收到错误 502 Bad Gateway。 В консоли: connect() failed (111: Connection refused) while connecting to upstream, client: 111.11.0.1, server: localhost, request: "GET /api/v1/clients/ HTTP/1.1", upstream: "http://111.11.0.2:80/api/v1/clients/", host: "localhost" 如果我访问地址:“http://localhost:8000/api/v1/clients/”,一切都很好。我的错误是什么?

nginx:

upstream backend {
    server 127.0.0.1:8000;
    server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name localhost;

    location /api/v1/clients/ {
        proxy_pass http://backend_client/api/v1/clients/; 
    }
}

docker:

services:
  backend_client:
    build: ./Client
    volumes:
      - ./Client/:/app
    ports:
      - "8000:8000"
    restart: always
    command:
      "gunicorn --bind=0.0.0.0:8000 django_app.wsgi"
  nginx:
    image: nginx:1.17
    container_name: ngx
    ports:
      - "80:80"
    volumes:
      - ./nginx:/etc/nginx/conf.d
    depends_on:
      - backend_client

更改您的 NGINX 配置。确保您正在阅读有关

的一些基本信息

您的后端将在您的 nginx 容器中作为 backend_client 提供。上游是backend。您的应用程序仍在端口 8000 上列出,此信息很重要。所以告诉 NGINX :).

upstream backend {
    server backend_client:8000;
}

server {
    listen 80;

    location /api/v1/clients/ {
        proxy_pass http://backend/; 
    }
}