Dockerized NGINX/STRAPI/DB/CLIENT 设置

Dockerized NGINX/STRAPI/DB/CLIENT 设置

为了发展目的我想实现这一点:Docker 化的 strapi 应用程序

但是路由到 /dashboard/ 时出现问题。它应该从 strapi 容器加载静态文件,但并没有这样做。我认为该问题是由于 Nginx 配置不当造成的。这是我的默认配置文件文件:

upstream client {
  # CRA dev server
  server client:3000;
}

upstream strapi {
  # strapi server
  server strapi:1337;
}

server {
  listen 80;

  location / {
    proxy_pass http://client;
  }

  location /sockjs-node {
    proxy_pass http://client;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
  }

  # Strapi API and Admin
        location /api/v1/ {
            rewrite ^/api/v1(.*)$ /$1 break;
            proxy_pass http://strapi;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $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-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_pass_request_headers on;
        }

        # Strapi Admin panel
        location /dashboard/ {
            proxy_pass http://strapi/dashboard/;
           
        }
      
    
}

这是docker-compose.dev.yaml文件

version: '3'

services:
  nginx:
    restart: always
    container_name: nginx
    build:
      dockerfile: Dockerfile.dev
      context: ./nginx
    ports:
      - '3050:80'
    depends_on:
      - client
      - strapi
    networks:
      - api-network

  strapi:
    image: strapi/strapi
    container_name: strapi
    restart: unless-stopped
 
    environment:
      NODE_ENV: development
      DATABASE_CLIENT: mongo
      DATABASE_NAME: strapidata
      DATABASE_HOST: strapidata
      DATABASE_PORT: 27017
      DATABASE_USERNAME: 
      DATABASE_PASSWORD: 
    networks:
      - api-network
    volumes:
      - ./strapi:/srv/app
    ports:
      - '1337:1337'
    depends_on:
      - strapidata

  strapidata:
    image: mongo
    container_name: strapidata
    restart: unless-stopped

    environment:
      MONGO_INITDB_ROOT_USERNAME: 
      MONGO_INITDB_ROOT_PASSWORD: 
    networks:
      - api-network
    volumes:
      - ./mongoDB:/data/db
    ports:
      - '27017:27017'

  client:
    container_name: client
    build:
      context: ./client
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - ./client:/app
    ports:
      - 3000:3000
    environment:
      - CHOKIDAR_USEPOLLING=true
    stdin_open: true
    tty: true
    depends_on:
      - strapi
    networks:
      - api-network
networks:
  api-network:
    driver: bridge

NGINX=> api/v1/ 运行正常,但未传递 /dashboard/ 的资产。来自 strapi 容器的资产未加载到 /dashboard。有人试过吗?

相关内容