File tree Expand file tree Collapse file tree 2 files changed +61
-21
lines changed
Expand file tree Collapse file tree 2 files changed +61
-21
lines changed Original file line number Diff line number Diff line change 1- FROM node:20-alpine AS dependencies-env
1+ # 建置階段
2+ FROM node:20-alpine AS build
23RUN npm i -g pnpm
3- COPY . /app
4-
5- FROM dependencies-env AS development-dependencies-env
6- COPY ./package.json pnpm-lock.yaml /app/
74WORKDIR /app
5+ COPY package.json pnpm-lock.yaml ./
86RUN pnpm i --frozen-lockfile
9-
10- FROM dependencies-env AS production-dependencies-env
11- COPY ./package.json pnpm-lock.yaml /app/
12- WORKDIR /app
13- RUN pnpm i --prod --frozen-lockfile
14-
15- FROM dependencies-env AS build-env
16- COPY ./package.json pnpm-lock.yaml /app/
17- COPY --from=development-dependencies-env /app/node_modules /app/node_modules
18- WORKDIR /app
7+ COPY . .
8+ ARG VITE_APP_API_URL
9+ ENV VITE_APP_API_URL=${VITE_APP_API_URL}
1910RUN pnpm build
2011
21- FROM dependencies-env
22- COPY ./package.json pnpm-lock.yaml /app/
23- COPY --from=production-dependencies-env /app/node_modules /app/node_modules
24- COPY --from=build-env /app/build /app/build
25- WORKDIR /app
26- CMD ["pnpm" , "start" ]
12+ # 運行階段
13+ FROM nginx:alpine
14+ # 複製檔案
15+ COPY --from=build /app/build/client /usr/share/nginx/html/
16+ # 複製 nginx 配置模板
17+ COPY nginx.conf /etc/nginx/templates/default.conf.template
18+ # 使用 envsubst 來替換環境變數
19+ CMD ["/bin/sh" , "-c" , "envsubst '${VITE_APP_API_URL}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" ]
Original file line number Diff line number Diff line change 1+ server {
2+ listen 80 ;
3+ include /etc/nginx/mime.types ;
4+
5+ root /usr/share/nginx/html;
6+ index index .html;
7+
8+ # API Proxy 設定
9+ location /v2/ {
10+ proxy_pass ${ VITE_APP_API_URL} ;
11+
12+ # SSL 設定
13+ proxy_ssl_server_name on;
14+ proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
15+
16+ # 基本代理設定
17+ proxy_http_version 1.1;
18+ proxy_set_header Host $proxy_host ;
19+ proxy_set_header X-Real-IP $remote_addr ;
20+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
21+ proxy_set_header X-Forwarded-Proto $scheme ;
22+
23+ # 超時設定
24+ proxy_connect_timeout 60s ;
25+ proxy_send_timeout 60s ;
26+ proxy_read_timeout 60s ;
27+ }
28+
29+ # 其他路由設定保持不變
30+ location /react-main-2024 -w2 {
31+ alias /usr/share/nginx/html;
32+ try_files $uri $uri / /index .html;
33+
34+ location ~ \.js$ {
35+ add_header Content-Type "application/javascript" ;
36+ }
37+ }
38+
39+ location /react-main-2024 -w2/assets/ {
40+ alias /usr/share/nginx/html/assets/;
41+ add_header Cache-Control "public, max-age=31536000, immutable" ;
42+ }
43+
44+ location = / {
45+ return 301 /react-main-2024 -w2/;
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments