A
A
Andrew2020-02-25 16:01:45
Django
Andrew, 2020-02-25 16:01:45

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

spoiler

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/



settings.py
spoiler
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"),
)


docker-compose.prod.yml
spoiler

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:


nginx config
spoiler

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/;
    }

}



I performed the collectstatic command in two ways. None worked 1. docker-compose -f docker- compose.prod.yml exec web python
manage.py collectstatic --no-input --clear collectstatic --no-input --clear The nginx server is running requests go through it. But it does not see static files. Error 404 Please tell me where I made a mistake, the head is boiling.
ENTRYPOINT ["/var/code/entrypoint.prod.sh"]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2020-02-26
@fugro

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 question

Ask a Question

731 491 924 answers to any question