Docker 码头工人Tiemout上游Gunicorn(坏网关502)

Docker 码头工人Tiemout上游Gunicorn(坏网关502),docker,ubuntu,nginx,gunicorn,Docker,Ubuntu,Nginx,Gunicorn,我正试图从我的Ubuntu服务器上运行一个基于Django、Docker、Nginx和Gunicorn的平台构建 在问您之前,我正在阅读关于我的问题的文章,我在nginx.conf上做了如下操作: location / { proxy_read_timeout 300s; proxy_connect_timeout 75s; ... } 然后,在我的Gunicorn设置中: CMD ["gunicorn", "--bind", &

我正试图从我的Ubuntu服务器上运行一个基于Django、Docker、Nginx和Gunicorn的平台构建

在问您之前,我正在阅读关于我的问题的文章,我在nginx.conf上做了如下操作:

location / {
    proxy_read_timeout 300s;
    proxy_connect_timeout 75s;
    ...
}
然后,在我的Gunicorn设置中:

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "-t 90", "config.wsgi:application"]
问题仍然存在,服务器始终返回:502坏网关。当我尝试访问:

http://34.69.240.210:8000/admin/
从浏览器,服务器重定向到

http://34.69.240.210:8000/admin/login/?next=/admin/
但请显示错误:

我的Dockerfile

FROM python:3.8
  
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code
COPY . /code/

RUN pip install -r requirements.txt

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "-t 90", "config.wsgi:application"]
version: "3.8"
  
services:
  django_app:
    build: .
    volumes:
      - static:/code/static
      - .:/code

  nginx:
    image: nginx:1.15
    ports:
      - 8000:8000
    volumes:
      - ./config/nginx/conf.d:/etc/nginx/conf.d
      - static:/code/static
    depends_on:
      - django_app

volumes:
  .:
  static:
Mydocker compose.yml

FROM python:3.8
  
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code
COPY . /code/

RUN pip install -r requirements.txt

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "-t 90", "config.wsgi:application"]
version: "3.8"
  
services:
  django_app:
    build: .
    volumes:
      - static:/code/static
      - .:/code

  nginx:
    image: nginx:1.15
    ports:
      - 8000:8000
    volumes:
      - ./config/nginx/conf.d:/etc/nginx/conf.d
      - static:/code/static
    depends_on:
      - django_app

volumes:
  .:
  static:
我的Nginx文件:

upstream django_server {
    server django_app:8000 fail_timeout=0;
}

server {
    listen 8000;
    server_name 34.69.240.210;

    keepalive_timeout 5;
    client_max_body_size 4G;

    location / {
        proxy_read_timeout 300s;
        proxy_connect_timeout 75s;
        proxy_pass http://django_server;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }
}
知道我能做些什么来修复它吗

谢谢。

好吧,请记录在案

我的问题是数据库连接。我的Docker容器无法连接到potsgres本地数据库

因此,我在postgresql.conf中添加了这一行:

listen_addresses = '*'
然后,我将这一行添加到pg_hba.conf

host all all 0.0.0.0/0 md5
重新启动Postgres:

sudo service postgresql restart
我的主机postgres ip:

172.17.0.1
从docker内部进行测试:

psql -U myuser -d databasename -h 172.17.0.1 -W
完成!:)