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; + # } +}