charles_c преди 5 месеца
родител
ревизия
30bcbcb832
променени са 4 файла, в които са добавени 16 реда и са изтрити 5 реда
  1. 1 5
      Dockerfile.prod
  2. 1 0
      docker-compose.prod.yml
  3. 12 0
      next.config.js
  4. 2 0
      nginx/default.conf

+ 1 - 5
Dockerfile.prod

@@ -50,9 +50,6 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
 COPY --from=builder /app/node_modules ./node_modules
 COPY --from=builder /app/node_modules ./node_modules
 COPY --from=builder /app/package.json ./package.json
 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
-
 # 设置权限
 # 设置权限
 RUN mkdir -p /app/public/uploads
 RUN mkdir -p /app/public/uploads
 RUN chown -R nextjs:nodejs /app/public/uploads
 RUN chown -R nextjs:nodejs /app/public/uploads
@@ -60,10 +57,9 @@ RUN chown -R nextjs:nodejs /app/public/uploads
 # 临时提升权限以允许写入上传目录
 # 临时提升权限以允许写入上传目录
 USER root
 USER root
 RUN chmod 777 /app/public/uploads
 RUN chmod 777 /app/public/uploads
-USER nextjs
 
 
 # 设置为非 root 用户
 # 设置为非 root 用户
-# USER nextjs
+USER nextjs
 
 
 # 暴露端口
 # 暴露端口
 EXPOSE 3000
 EXPOSE 3000

+ 1 - 0
docker-compose.prod.yml

@@ -32,6 +32,7 @@ services:
     volumes:
     volumes:
       - ./nginx:/etc/nginx/conf.d
       - ./nginx:/etc/nginx/conf.d
       - ./logs/nginx:/var/log/nginx
       - ./logs/nginx:/var/log/nginx
+      - ./public/uploads:/app/public/uploads:ro
     depends_on:
     depends_on:
       - nextjs
       - nextjs
     restart: unless-stopped  # 添加自动重启策略
     restart: unless-stopped  # 添加自动重启策略

+ 12 - 0
next.config.js

@@ -0,0 +1,12 @@
+/** @type {import('next').NextConfig} */
+const nextConfig = {
+  output: "standalone",
+  env: {
+    MONGODB_URI: process.env.MONGODB_URI,
+  },
+  images: {
+    domains: ["match.dzhhzy.com"],
+  },
+};
+
+module.exports = nextConfig;

+ 2 - 0
nginx/default.conf

@@ -22,8 +22,10 @@ server {
 
 
     location /uploads {
     location /uploads {
         alias /app/public/uploads;
         alias /app/public/uploads;
+        try_files $uri $uri/ =404;
     }
     }
 
 
+
     # 添加健康检查路由
     # 添加健康检查路由
     location /health {
     location /health {
         access_log off;
         access_log off;