build(deployment): 更新生产环境配置并添加 Nginx 配置

- 修改 .env.production 中的 VITE_APP_BASE_API 为 /dev-api
- 新增 nginx/default.conf 配置文件,设置 Nginx 服务器配置
- 更新 Dockerfile,使用内部 Nexus 仓库作为 npm registry
- 调整 vite.config.ts 中的开发代理端口为 18080
This commit is contained in:
cuijiawang 2025-07-31 15:02:58 +08:00
parent 1104614d72
commit 8fcdf09999
4 changed files with 47 additions and 4 deletions

View File

@ -13,4 +13,5 @@ VITE_CDN = false
VITE_COMPRESSION = "none"
# 后端地址
VITE_APP_BASE_API = '/prod-api'
# VITE_APP_BASE_API = '/prod-api'
VITE_APP_BASE_API = '/dev-api'

View File

@ -4,7 +4,7 @@ WORKDIR /app
RUN corepack enable
RUN corepack prepare pnpm@7.32.1 --activate
RUN npm config set registry https://registry.npmmirror.com
RUN npm config set registry http://nexus:8081/repository/npm-public/
COPY .npmrc package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
@ -15,6 +15,9 @@ RUN pnpm build
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY nginx/default.conf /etc/nginx/conf.d/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]

39
nginx/default.conf Normal file
View File

@ -0,0 +1,39 @@
server {
listen 80;
server_name localhost;
#gzip config
gzip on;
gzip_buffers 32 4k;
gzip_comp_level 6;
gzip_min_length 100;
gzip_types application/javascript text/css text/xml;
gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件支持正则。此处表示ie6及以下不启用gzip因为ie低版本不支持
gzip_vary on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
location ~ ^/dev-api/(?<path>.*) {
proxy_pass http://172.18.0.25:18080/$path$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /nginx-health {
access_log off;
return 200 "OK";
add_header Content-Type text/plain;
}
}

View File

@ -45,7 +45,7 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
// 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
proxy: {
"/dev-api": {
target: "http://localhost:8080",
target: "http://localhost:18080",
changeOrigin: true,
rewrite: path => path.replace(/^\/dev-api/, "")
}