python - 開發(fā)環(huán)境下使用 Docker + Gunicorn + Nginx 只能看到 Niginx 歡迎界面
問題描述
在開發(fā)環(huán)境下使用 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 沒有把請求轉發(fā)給 Gunicorn?求指點!
問題解答
回答1:請進入nginx容器看清楚配置文件的位置
相關文章:
1. angular.js - webpack build后的angularjs路由跳轉問題2. java - web項目中,用戶登陸信息存儲在session中好 還是cookie中好,取決于什么?3. java - Activity中的成員變量被賦值之后,Activity被回收的時候內存才會被釋放嗎4. Discuz! Q 有人用過嗎?5. 數(shù)組按鍵值封裝!6. 我寫的哪里有錯?請大神幫忙查看一下。7. 請求一個數(shù)據(jù)返回內容為空或者錯誤如何再次請求幾次8. 使用list和each配合,的作業(yè),輸出一行后,如何換行9. php由5.3升級到5.6后,登錄網站,返回的是php代碼,不是登錄界面,各位大神有知道的嗎?10. 為什么bindClass訪問不了的?
