feat(frontend): 添加 Docker 部署配置和生产环境变量

- Dockerfile:多阶段构建,node:20-alpine 编译 Vue3,
  nginx:alpine 提供静态资源服务,使用国内 npm 镜像加速
- nginx.conf:配置 Vue Router history 模式(try_files),
  /api/ 和 /uploads/ 反向代理到后端容器
- .env.production:生产环境 API 地址(8.148.151.56:3001)
- .gitignore:放开 .env.production 提交权限(无敏感信息)
This commit is contained in:
tonytech 2026-02-28 19:32:45 +08:00
parent 3a921250c3
commit 92071e5ba6
4 changed files with 40 additions and 1 deletions

3
.gitignore vendored
View File

@ -19,7 +19,8 @@ target/
# 环境变量(含敏感信息,不提交)
.env
.env.local
.env.production
# .env.production 只含 API 地址,允许提交
# .env.production
# 保留开发环境配置(可按需注释掉)
# .env.development

View File

@ -0,0 +1,3 @@
VITE_API_BASE_URL=http://8.148.151.56:3001/api/v1
VITE_SERVER_BASE_URL=http://8.148.151.56:3001
VITE_APP_TITLE=幼儿阅读教学服务平台

View File

@ -0,0 +1,14 @@
# 阶段一:编译
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install --registry=https://registry.npmmirror.com
COPY . .
RUN npx vite build
# 阶段二Nginx 服务
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@ -0,0 +1,21 @@
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
# Vue Router history 模式支持
location / {
try_files $uri $uri/ /index.html;
}
# 反向代理后端 API
location /api/ {
proxy_pass http://backend:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /uploads/ {
proxy_pass http://backend:3001;
}
}