charles_c 5 months ago
parent
commit
64cacdf1dc
3 changed files with 12 additions and 5 deletions
  1. 6 3
      Dockerfile.prod
  2. 2 2
      docker-compose.prod.yml
  3. 4 0
      nginx/default.conf

+ 6 - 3
Dockerfile.prod

@@ -53,15 +53,18 @@ COPY --from=builder /app/package.json ./package.json
 # 创建 uploads 目录并设置权限
 # RUN mkdir -p /app/public/uploads && chown -R nextjs:nodejs /app/public && chown -R nextjs:nodejs /app/public/uploads
 
-USER root
 # 设置权限
 RUN mkdir -p /app/public/uploads
-RUN chown -R nextjs:nodejs /app/public
 RUN chown -R nextjs:nodejs /app/public/uploads
 
-# 设置为非 root 用户
+# 临时提升权限以允许写入上传目录
+USER root
+RUN chmod 777 /app/public/uploads
 USER nextjs
 
+# 设置为非 root 用户
+# USER nextjs
+
 # 暴露端口
 EXPOSE 3000
 

+ 2 - 2
docker-compose.prod.yml

@@ -16,7 +16,7 @@ services:
     restart: unless-stopped  # 添加自动重启策略
     volumes:
       # - nextjs-uploads:/app/public/uploads
-      - ./public/uploads:/app/public/uploads:rw,z
+      - uploads_data:/app/public/uploads
     
   mongodb:
     image: mongo
@@ -38,7 +38,7 @@ services:
 
 volumes:
   mongodb_data:
-  # nextjs-uploads:
+  uploads_data:
 
 networks:
   default:

+ 4 - 0
nginx/default.conf

@@ -20,6 +20,10 @@ server {
         proxy_read_timeout 60s;
     }
 
+    location /uploads {
+        alias /app/public/uploads;
+    }
+
     # 添加健康检查路由
     location /health {
         access_log off;