错误502 Bad Gateway Nginx和Celery Workers

时间:2017-03-14 15:49:37

标签: nginx celery docker-compose gunicorn

我正在尝试在Gunicorn服务器中运行与Nginx,Celery,RabbitMQ和Django的docker-compose。没有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;
    }

}

有谁知道可能导致此问题的原因? stackoverflow上报告的大多数问题都不涉及芹菜工人面前的代理服务器

1 个答案:

答案 0 :(得分:0)

问题是我必须指定所有css文件的位置,并在docker-compose.yml文件中指定我的docker卷。事后,一切都运作良好。相对微不足道