diff --git a/Dockerfile b/Dockerfile index c48f225..7c701ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,9 @@ RUN npm run build # 生产阶段 FROM nginx:stable-alpine as production-stage +# 将自定义的 nginx 配置复制到容器中 +COPY nginx.conf /etc/nginx/conf.d/default.conf + # 将构建好的文件复制到 nginx 目录 COPY --from=build-stage /app/dist /usr/share/nginx/html/ # 将 static 目录下的文件直接复制到网站根目录 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..6fd8318 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # 启用 gzip + gzip on; + gzip_comp_level 6; + gzip_min_length 1000; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + gzip_vary on; + + # 支持 Vue Router 的 history 模式 + location / { + try_files $uri $uri/ /index.html; + } + + # 缓存静态资源 + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { + expires 30d; + add_header Cache-Control "public, no-transform"; + } +} \ No newline at end of file