A
A
Alexander Bondarenko2021-08-26 16:17:23
Django
Alexander Bondarenko, 2021-08-26 16:17:23

How to fix 404 error on page reload?

There is a site, a backend on django, a frontend on React, I set up separate docker files for them, and a common docker-compose, launched it, everything works, but when reloading the pages of the site, a 404 error appears, if you just switch from the main or others, then everything is fine. Also, the loading of static and media files in django does not work correctly, please tell me how to fix it?
nginx

upstream api{
    server backend:8000;
}

upstream admin{
    server backend:8000;
}

server{

    listen 8080;

    location / {
      root /var/www/react;
    }

    location ~ ^/api {
        proxy_pass http://api;
        proxy_set_header Host $http_host;
    }
    location ~ ^/admin {
        proxy_pass http://admin;
        proxy_set_header Host $http_host;
    }

    location /django_static/ {
        root /var/www/garagedoors;
    }

    location /django_media/ {
        root /var/www/garagedoors;
    }

}


Dockerfile for react

FROM node:14.17
WORKDIR /react
COPY . .
RUN npm rebuild node-sass
RUN npm run build


Dockerfile for Django

FROM python:3.8
ENV PYTHONUNBUFFERED 1
WORKDIR /django
COPY src/requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY /src .


docker-compose
version: '3'

services:
  backend:
    build:
      context: ./django
    command: gunicorn app.wsgi --bind 0.0.0.0:8000
    ports:
      - "8000:8000"
  frontend:
    build:
      context: ./react/gdr
    volumes:
      - react_build:/react/build
  nginx:
    image: nginx:latest
    ports:
        - 80:8080
    volumes:
      - ./nginx/nginx-setup.conf:/etc/nginx/conf.d/default.conf:ro
      - react_build:/var/www/react
    depends_on:
      - backend
      - frontend
volumes:
  react_build:

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question