【发布时间】:2021-03-07 17:55:34
【问题描述】:
我正在尝试从我的 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 Bad Gateway。当我尝试访问:
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"]
我的 docker-compose.yml:
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 ubuntu nginx gunicorn