File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Stage 1: Build
2+ FROM node:20-alpine AS builder
3+ WORKDIR /app
4+ RUN npm install -g pnpm
5+ COPY package.json pnpm-lock.yaml ./
6+ RUN pnpm install --frozen-lockfile
7+ COPY . .
8+ RUN pnpm build
9+
10+ # Stage 2: Serve via nginx
11+ FROM nginx:alpine AS runner
12+ COPY --from=builder /app/.output/public /usr/share/nginx/html
13+ COPY nginx.conf /etc/nginx/conf.d/default.conf
14+ EXPOSE 80
15+ CMD ["nginx" , "-g" , "daemon off;" ]
Original file line number Diff line number Diff line change 1+ server {
2+ listen 80 ;
3+ server_name _;
4+ root /usr/share/nginx/html;
5+ index index .html;
6+
7+ # SPA fallback — 所有路由交给 index.html 处理
8+ location / {
9+ try_files $uri $uri / /index .html;
10+ }
11+
12+ # API 反向代理到后端
13+ location /api/ {
14+ proxy_pass http ://backend:3000 /;
15+ proxy_set_header Host $host ;
16+ proxy_set_header X-Real-IP $remote_addr ;
17+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
18+ proxy_set_header X-Forwarded-Proto $scheme ;
19+ }
20+
21+ # 静态资源缓存
22+ location ~ * \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
23+ expires 1y ;
24+ add_header Cache-Control "public, immutable" ;
25+ }
26+
27+ # gzip
28+ gzip on;
29+ gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript;
30+ gzip_min_length 1024 ;
31+ }
You can’t perform that action at this time.
0 commit comments