From 3125a1e994768988be1f4f09357f3f5e40208111 Mon Sep 17 00:00:00 2001 From: "suguo.yao" Date: Mon, 24 Feb 2025 23:04:35 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E9=83=A8=E7=BD=B2=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E4=B8=BA/mobile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- Dockerfile | 22 +++++++++++++--------- nginx.conf | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 nginx.conf diff --git a/.env b/.env index ec6e2c6..22b61b7 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -VITE_APP_PUBLIC_PATH=/ +VITE_APP_PUBLIC_PATH=/mobile/ VITE_APP_PREVIEW=true VITE_APP_API_BASE_URL=/api VITE_APP_OUT_DIR=dist diff --git a/Dockerfile b/Dockerfile index 0e5a5f9..aef1574 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,21 @@ FROM nginx:1.25.3-alpine -LABEL "authors"="suguo.yao" -LABEL "email"="ysg@myschools.me" +LABEL authors="suguo.yao" +LABEL email="ysg@myschools.me" ENV TZ=Asia/Shanghai \ - LANG=C.UTF-8 \ - APP_DIR=/usr/share/nginx/html + LANG=C.UTF-8 \ + APP_DIR=/usr/share/nginx/html -COPY dist/. ${APP_DIR} +# 创建目标目录并复制构建产物 +RUN mkdir -p ${APP_DIR}/mobile +COPY dist/. ${APP_DIR}/mobile/ -WORKDIR ${APP_DIR} +# 用自定义Nginx配置覆盖默认配置 +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# 设置时区 +RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \ + && echo ${TZ} > /etc/timezone EXPOSE 80 - -RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \ - && echo ${TZ} > /etc/timezone \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..2789d0a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name localhost; + + location /mobile { + # 关键配置:指向构建产物的物理路径 + alias /usr/share/nginx/html/mobile; + + # 处理Vue路由的HTML5 History模式 + try_files $uri $uri/ /mobile/index.html; + + # 确保正确识别文件类型 + types { + text/html html; + application/javascript js; + text/css css; + } + } + + # 可选:重定向根路径到/mobile(按需启用) + # location = / { + # return 301 /mobile; + # } +}