python - 开发环境下使用 Docker + Gunicorn + Nginx 只能看到 Niginx 欢迎界面
问题描述
在开发环境下使用 Docker + Gunicorn + Nginx 来运行 Django,服务器启动后只能看到 Nginx 欢迎界面。
Dockerfile 如下:
django:
FROM python:3.5ENV PYTHONUNBUFFERED 1RUN groupadd -r django && useradd -r -g django djangoCOPY ./requirements.txt /requirements.txtRUN pip install --no-cache-dir -r /requirements.txt && rm -rf /requirements.txtCOPY ./compose/django/gunicorn.sh /RUN sed -i ’s/r//’ /gunicorn.sh && chmod +x /gunicorn.sh && chown django /gunicorn.shCOPY . /appRUN chown -R django /appRUN mkdir /staticRUN chown -R django /staticUSER djangoWORKDIR /app
nginx:
FROM nginx:latestADD nginx.conf /etc/nginx/sites-enabled/django_blog.conf
gunicorn.sh
#!/bin/shpython /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 builddocker-compose up
似乎是 Nginx 没有把请求转发给 Gunicorn?求指点!
问题解答
回答1:请进入nginx容器看清楚配置文件的位置
相关文章:
1. javascript - 读js权威指南“作为值得函数”产生了疑惑,求释疑2. 请问带渐变背景的进度条如何实现?求给点思路3. file - Python如何读文件内容修改后写回原文件4. python中merge后文件莫名变得非常大5. javascript - 为什么 process.stdin 会有 write 方法◔ ‸◔?6. boostrap怎么在移动端不显示sidebar?7. android - 使用listview加载不同item,数据填充错误。8. python3.x - python中的虚拟环境怎样设置一直处于激活状态9. javascript - 关于js原生事件的绑定与解除绑定10. mysql - 数据库建字段,默认值空和empty string有什么区别 110