kevin1207 commited on
Commit
31d9fe2
·
verified ·
1 Parent(s): 43b007b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -0
Dockerfile CHANGED
@@ -27,8 +27,23 @@ RUN pnpm build
27
 
28
  # production stage
29
  FROM nginx:stable-alpine AS production-stage
 
 
 
 
 
 
 
 
 
30
  COPY --from=build-stage /app/dist /usr/share/nginx/html
31
  COPY --from=build-stage /app/nginx.conf /etc/nginx/conf.d/default.conf
 
 
 
 
 
 
32
  EXPOSE 80
33
  CMD ["nginx", "-g", "daemon off;"]
34
 
 
27
 
28
  # production stage
29
  FROM nginx:stable-alpine AS production-stage
30
+ # 创建必要的 Nginx 目录并设置权限
31
+ RUN mkdir -p /var/cache/nginx && \
32
+ mkdir -p /var/log/nginx && \
33
+ mkdir -p /etc/nginx/conf.d && \
34
+ chown -R nginx:nginx /var/cache/nginx && \
35
+ chown -R nginx:nginx /var/log/nginx && \
36
+ chown -R nginx:nginx /etc/nginx/conf.d
37
+ # 修改 nginx.conf 的用户设置
38
+ RUN sed -i 's/user nginx/user nginx/g' /etc/nginx/nginx.conf
39
  COPY --from=build-stage /app/dist /usr/share/nginx/html
40
  COPY --from=build-stage /app/nginx.conf /etc/nginx/conf.d/default.conf
41
+
42
+ # 确保 Nginx 目录的权限正确
43
+ RUN chown -R nginx:nginx /usr/share/nginx/html && \
44
+ chmod -R 755 /usr/share/nginx/html
45
+ # 使用非 root 用户运行
46
+ USER nginx
47
  EXPOSE 80
48
  CMD ["nginx", "-g", "daemon off;"]
49