diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..95f55cb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# 构建阶段 +FROM node:16-alpine as builder + +# 设置工作目录 +WORKDIR /app + +# 复制 package.json 和 package-lock.json +COPY package*.json ./ + +# 安装依赖 +RUN npm install + +# 复制源代码 +COPY . . + +# 构建项目 +RUN npm run build + +# 生产阶段 +FROM nginx:alpine + +# 复制构建产物到 Nginx 目录 +COPY --from=builder /app/dist /usr/share/nginx/html + +# 复制 Nginx 配置文件(如果需要自定义配置) +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# 暴露端口 +EXPOSE 80 + +# 启动 Nginx +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..eacb99e --- /dev/null +++ b/nginx.conf @@ -0,0 +1,23 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html index.htm; + + location / { + try_files $uri $uri/ /index.html; + } + + # 配置 API 代理(根据实际需求修改) + location /api { + proxy_pass http://backend-service; # 替换为实际的后端服务地址 + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file