登录  /  注册
python - 开发环境下使用 Docker + Gunicorn + Nginx 只能看到 Niginx 欢迎界面
滿天的星座
滿天的星座 2017-06-16 09:19:02
[Docker讨论组]

在开发环境下使用 Docker + Gunicorn + Nginx 来运行 Django,服务器启动后只能看到 Nginx 欢迎界面。

Dockerfile 如下:

django:

FROM python:3.5

ENV PYTHONUNBUFFERED 1

RUN groupadd -r django \
    && useradd -r -g django django

COPY ./requirements.txt /requirements.txt
RUN pip install --no-cache-dir -r /requirements.txt \
    && rm -rf /requirements.txt

COPY ./compose/django/gunicorn.sh /
RUN sed -i 's/\r//' /gunicorn.sh \
    && chmod +x /gunicorn.sh \
    && chown django /gunicorn.sh

COPY . /app

RUN chown -R django /app

RUN mkdir /static
RUN chown -R django /static

USER django

WORKDIR /app

nginx:

FROM nginx:latest
ADD nginx.conf /etc/nginx/sites-enabled/django_blog.conf

gunicorn.sh

#!/bin/sh
python /app/manage.py collectstatic --noinput
/usr/local/bin/gunicorn blogproject.wsgi -w 4 -b 127.0.0.1:8000 --chdir=/app

nginx.conf 配置:

server {
    charset utf-8;
    listen 80 default_server;

    location /static {
        alias /app/static;
    }

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:8000;
    }
}

docker-compose.yml

version: '3'

services:
  django:
    build:
      context: .
      dockerfile: ./compose/django/Dockerfile
    command: /gunicorn.sh

  nginx:
    build: ./compose/nginx
    depends_on:
      - django

    ports:
      - "80:80"

运行命令:
docker-compose build
docker-compose up

似乎是 Nginx 没有把请求转发给 Gunicorn?求指点!

滿天的星座
滿天的星座

全部回复(1)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号