我在django開發環境中使用Docker,Gunicorn,Nginx,但只能看到nginx的歡迎頁面。在django開發環境中使用Docker,Gunicorn,Nginx,但只能看到nginx的歡迎頁面?
我的搬運工文件:
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;
}
}
泊塢窗,compose.yml:
泊塢窗,撰寫構建
碼頭工人,組成了
看來Nginx的不及格:我跑
version: '3'
services:
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile
command: /gunicorn.sh
nginx:
build: ./compose/nginx
depends_on:
- django
ports:
- "80:80"
命令請求gunicorn?
更新:
據@Robert建議,事情的來龍去脈。但是,由於靜態文件在django容器中,所以我不知道如何讓nginx託管它們?我試圖按照Volume configuration reference這樣設置卷:
version: '3'
services:
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile
volumes:
- static-volume:/app/static
command: /gunicorn.sh
nginx:
build: ./compose/nginx
volumes:
- static-volume:/app/static
depends_on:
- django
ports:
- "0.0.0.0:80:80"
volumes:
static-volume:
但它似乎不起作用?我應該如何讓nginx訪問django容器中的靜態文件?謝謝!
你似乎沒有做過什麼nginx的容器Django的一個連接。 –
@yangxg我已經更新了我的答案 – Robert