diff --git a/.env.production b/.env.production index 6ecab1d..1ea95a7 100644 --- a/.env.production +++ b/.env.production @@ -13,4 +13,5 @@ VITE_CDN = false VITE_COMPRESSION = "none" # 后端地址 -VITE_APP_BASE_API = '/prod-api' \ No newline at end of file +# VITE_APP_BASE_API = '/prod-api' +VITE_APP_BASE_API = '/dev-api' diff --git a/Dockerfile b/Dockerfile index 5163975..9e842f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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;"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..ec35c6d --- /dev/null +++ b/nginx/default.conf @@ -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/(?.*) { + 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; + } +} diff --git a/vite.config.ts b/vite.config.ts index 78ff3a8..4453503 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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/, "") }