刷新我的Django-React-Docker应用程序时,Nginx服务器返回404

时间:2020-11-08 07:32:39

标签: reactjs django docker nginx

我对我的react-django应用程序进行了docker化。 react代码被变成一个静态文件夹,该文件夹由nginx服务器提供服务。除了当我重新加载页面时,一切都工作正常。如果我重新加载页面,将显示404页面。另外,出现问题时,React不会显示404页面。我想这与我的服务器配置有关。

default.config

server {
    listen 80;

    location / {
        proxy_pass http://frontend:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }

    location /api {
        proxy_pass http://backend:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }

    location /admin {
        proxy_pass http://backend:8000/admin;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }

    location /nginx-health-check {
        access_log off;
        return 200;
    }

 }

我的docker-compose

version: "3"
services:
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    ports:
      - 8000:8000
    volumes:
      - ./backend:/app
      - ./backend/media:/app/media
      - ./backend/static:/app/static
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile-prod
    ports:
      - 3000:80
    volumes:
      - ./frontend/src:/app/src
  nginx:
    build:
      context: ./nginx
      dockerfile: Dockerfile
    ports:
      - 80:80

我从这个仓库中得到了这段代码:https://github.com/kasper190/django_k8s/tree/master/code

0 个答案:

没有答案