Answer the question
In order to leave comments, you need to log in
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;
}
}
FROM node:14.17
WORKDIR /react
COPY . .
RUN npm rebuild node-sass
RUN npm run build
FROM python:3.8
ENV PYTHONUNBUFFERED 1
WORKDIR /django
COPY src/requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY /src .
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 questionAsk a Question
731 491 924 answers to any question