Commit 4c317d6e by zhangxingmin

push

parent 49fd9bd5
......@@ -22,11 +22,11 @@ RUN npm run build
# 生产阶段
FROM docker.m.daocloud.io/library/nginx:alpine
# 关键修改:直接复制 cffp 目录到 Nginx 根目录
COPY --from=builder /app/dist/cffp /usr/share/nginx/html
# 直接复制 dist 根目录到 Nginx 根目录(匹配容器内实际路径)
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 设置时区
# 保持时区和权限配置不变
RUN echo "https://mirrors.aliyun.com/alpine/v3.22/main/" > /etc/apk/repositories && \
echo "https://mirrors.aliyun.com/alpine/v3.22/community/" >> /etc/apk/repositories && \
apk update && \
......@@ -34,7 +34,6 @@ RUN echo "https://mirrors.aliyun.com/alpine/v3.22/main/" > /etc/apk/repositories
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
# 设置文件权限
RUN chown -R nginx:nginx /usr/share/nginx/html \
&& chmod -R 755 /usr/share/nginx/html
......
......@@ -2,18 +2,14 @@ server {
listen 8333;
server_name localhost;
root /usr/share/nginx/html;
root /usr/share/nginx/html; # 直接指向资源所在的根目录
index index.html;
# 确保正确的 MIME 类型
include /etc/nginx/mime.types;
# 静态资源直接返回,不经过 try_files
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y; # 静态资源缓存
# 静态资源处理(匹配实际 assets 目录)
location ~* \.(js|css|png|jpg|svg|woff2?|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public";
access_log off;
log_not_found off;
}
# 主应用路由(history 模式)
......@@ -22,11 +18,6 @@ server {
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
# 子应用 /cffp/ 路由(关键修正)
location /cffp/ {
try_files $uri $uri/ /index.html; # 改为指向根目录的 index.html
}
# 禁止访问 .env 文件
location ~ /\.env {
deny all;
......@@ -38,8 +29,4 @@ server {
location = /50x.html {
root /usr/share/nginx/html;
}
# 访问日志
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
}
......@@ -16,29 +16,27 @@ export default defineConfig({
}
},
// 开发服务器配置
server: {
port: 8080,
proxy: {
// 代理后端 API 请求
'/cffpApi': {
target: 'http://localhost:8080',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/cffpApi/, '')
}
}
},
// // 开发服务器配置
// server: {
// port: 8080,
// proxy: {
// // 代理后端 API 请求
// '/cffpApi': {
// target: 'http://localhost:8080',
// changeOrigin: true,
// rewrite: (path) => path.replace(/^\/cffpApi/, '')
// }
// }
// },
// 生产环境构建配置
build: {
outDir: 'dist/cffp', // 关键修改:输出目录改为 dist/cffp
assetsDir: 'assets', // 静态资源目录
outDir: 'dist', // 输出到 dist 根目录(而非 dist/cffp)
assetsDir: 'assets',
rollupOptions: {
output: {
// 确保生成的资源路径正确
assetFileNames: 'assets/[name].[hash].[ext]',
entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/[name].[hash].js',
entryFileNames: 'assets/[name].[hash].js'
assetFileNames: 'assets/[name].[hash].[ext]'
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment