python - 開發(fā)環(huán)境下使用 Docker + Gunicorn + Nginx 只能看到 Niginx 歡迎界面
問題描述
在開發(fā)環(huán)境下使用 Docker + Gunicorn + Nginx 來運(yùn)行 Django,服務(wù)器啟動(dòng)后只能看到 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'
運(yùn)行命令:docker-compose builddocker-compose up
似乎是 Nginx 沒有把請(qǐng)求轉(zhuǎn)發(fā)給 Gunicorn?求指點(diǎn)!
問題解答
回答1:請(qǐng)進(jìn)入nginx容器看清楚配置文件的位置
相關(guān)文章:
1. mysql - 字符串根據(jù)字典替換2. 請(qǐng)教使用PDO連接MSSQL數(shù)據(jù)庫插入是亂碼問題?3. node.js - nodejs開發(fā)中常用的連接mysql的庫4. mysql - 把一個(gè)表中的數(shù)據(jù)count更新到另一個(gè)表里?5. 視頻文件不能播放,怎么辦?6. flask - python web中如何共享登錄狀態(tài)?7. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場景下 ,會(huì)帶來哪些效率或者其他方面的好處8. node.js - 為什么微信的消息MsgId出現(xiàn)重復(fù)了,無法排重了。。9. MySQL 截短某一列的字符串10. mysql 查詢身份證號(hào)字段值有效的數(shù)據(jù)
