alexcdev1 vor 5 Monaten
Ursprung
Commit
2875bebb0d
3 geänderte Dateien mit 11 neuen und 7 gelöschten Zeilen
  1. 1 1
      Dockerfile.prod
  2. 5 1
      docker-compose.prod.yml
  3. 5 5
      nginx/default.conf

+ 1 - 1
Dockerfile.prod

@@ -45,7 +45,7 @@ RUN addgroup --system --gid 1001 nodejs
 RUN adduser --system --uid 1001 nextjs
 
 # 创建 uploads 目录并设置权限
-RUN mkdir -p /app/public/uploads && chown -R nextjs:nodejs /app/public && chmod 755 /app/public/uploads
+RUN mkdir -p /app/public/uploads && chown -R nextjs:nodejs /app/public
 
 # 复制必要文件
 COPY --from=builder /app/public ./public

+ 5 - 1
docker-compose.prod.yml

@@ -14,7 +14,10 @@ services:
     depends_on:
       - mongodb
     restart: unless-stopped  # 添加自动重启策略
-
+    volumes:
+      - nextjs-uploads:/app/public/uploads
+    user: root
+    
   mongodb:
     image: mongo
     volumes:
@@ -34,6 +37,7 @@ services:
 
 volumes:
   mongodb_data:
+  nextjs-uploads:
 
 networks:
   default:

+ 5 - 5
nginx/default.conf

@@ -26,11 +26,11 @@ server {
         return 200 'OK';
     }
 
-    location /uploads {
-        alias /app/public/uploads;
-        expires 30d;
-        add_header Cache-Control "public, max-age=2592000";
-    }
+    # location /uploads {
+    #     alias /app/public/uploads;
+    #     expires 30d;
+    #     add_header Cache-Control "public, max-age=2592000";
+    # }
 
     # Security headers
     add_header X-Frame-Options "SAMEORIGIN" always;