Answer the question
In order to leave comments, you need to log in
What folder does Django collect staticfiles into?
Help with static files in Django and Nginx. Already completely confused.
Deploy django app via gunicorn and nginx
Followed this tutorial
Dockerfile
FROM python:3.7-stretch
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
# Update base container install
RUN apt-get update
RUN apt-get upgrade -y
RUN mkdir /var/code
RUN mkdir /var/code/static
WORKDIR /var/code
# install dependencies
RUN pip install --upgrade pip
ADD requirements.txt /var/code/
RUN pip install -r requirements.txt
ADD . /var/code/
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'lrm', 'static'),
os.path.join(BASE_DIR, 'calcdist', 'static'),
os.path.join(BASE_DIR, "static"),
)
version: '3.7'
services:
web:
container_name: web
build: .
command: gunicorn geoApp.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_volume:/var/code/static
expose:
- 8000
env_file:
- ./prod.env
nginx:
container_name: nginx
image: nginx:1.17.8-alpine
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- 8989:8989
depends_on:
- web
volumes:
static_volume:
upstream application {
server web:8000;
}
server {
listen 8989;
server_name localhost;
location / {
proxy_pass http://application;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
alias /var/code/static/;
}
}
ENTRYPOINT ["/var/code/entrypoint.prod.sh"]
Answer the question
In order to leave comments, you need to log in
The problem was solved in the following way.
1. collectstatic to the django project folder
2. In the docker-compose file, added a folder with files to the nginx image via volume The result is the
following
version: '3.7'
services:
web:
container_name: web
build: .
command: gunicorn geoApp.wsgi:application --bind 0.0.0.0:8000
volumes:
- /var/code/static
expose:
- 8000
env_file:
- ./prod.env
nginx:
container_name: nginx
image: nginx:1.17.8-alpine
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./static:/var/code/static
ports:
- 8989:8989
depends_on:
- web
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question