错误 502 Bad Gateway Nginx 和 Celery Workers

Error 502 Bad Gateway Nginx and Celery Workers

我正在尝试 运行 docker-在 Gunicorn 服务器中与 Nginx、Celery、RabbitMQ 和 Django 组合。应用程序 运行 在没有 Nginx 的情况下很好,但在生产中我需要 Nginx 来提供静态文件,并在我添加它时从 Nginx 获得 Error 502 Bad Gateway

下面是 docker-compose:

version: "2"
services:
  web:
    build: ./web
    expose:
      - "8000"
    depends_on:
      - redis
      - postgres
      - rabbit
    volumes:
        - .:/app
    env_file: .env
    environment:
      DEBUG: 'true'
    command: /usr/local/bin/gunicorn api.wsgi:application -w 2 -b :8000

  nginx:
    build: ./nginx/
    ports:
      - "80:80"
    volumes:
      - /www/static
    volumes_from:
      - web

  rabbit:
    hostname: rabbit
    image: rabbitmq:latest
    environment:
        - RABBITMQ_DEFAULT_USER=admin
        - RABBITMQ_DEFAULT_PASS=mypass
    ports:
        - "5672:5672"
        - "15672:15672"

  postgres:
    image: postgres:latest
    volumes:
      - db-data:/var/lib/postgresql/data

  redis:
    image: redis:latest


volumes:
  db-data:

下面是我的 Nginx.conf 文件:

server {

    listen 80;
    server_name example.org;
    charset utf-8;

    location /static {
        alias /usr/src/app/static;
    }

    location / {
        proxy_pass http://web:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

有谁知道可能导致此问题的原因是什么? Whosebug 上报告的大多数问题都不会处理 celery worker 前面的代理服务器

问题是我必须为所有 css 文件指定位置,并在 docker-compose.yml 文件中指定我的 docker 卷。之后,一切正常。比较琐碎