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. python的文件讀寫問題?2. python - (初學者)代碼運行不起來,求指導,謝謝!3. mysql里的大表用mycat做水平拆分,是不是要先手動分好,再配置mycat4. window下mysql中文亂碼怎么解決??5. linux - 【已解決】fabric部署的Python項目Apache啟動之后提示403Forbidden該如何解決?6. nginx - pip install python庫報錯7. python - flask sqlalchemy signals 無法觸發8. javascript - js 對中文進行MD5加密和python結果不一樣。9. python - 如何判斷字符串為企業注冊名稱10. 為什么python中實例檢查推薦使用isinstance而不是type?
