Commit 5bae8896 by 晏艳红

添加Docker v2容器化部署支持

- 创建多阶段构建Dockerfile,优化镜像大小
- 添加docker-compose.yml用于开发环境
- 添加docker-compose.prod.yml用于生产环境
- 配置nginx反向代理和静态文件服务
- 添加健康检查和监控脚本
- 优化vite构建配置
- 包含完整的部署文档和快速启动脚本
parent 79299e07
# 依赖目录
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# 构建输出
dist/
build/
# Git相关
.git/
.gitignore
.gitattributes
# IDE和编辑器文件
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store
# 环境变量文件
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# 日志文件
logs/
*.log
# 运行时数据
pids/
*.pid
*.seed
*.pid.lock
# 覆盖率目录
coverage/
*.lcov
.nyc_output
# 缓存目录
.npm
.eslintcache
.cache
.parcel-cache
# 临时文件
tmp/
temp/
# 操作系统生成的文件
Thumbs.db
ehthumbs.db
.Spotlight-V100
.Trashes
# Docker相关文件
Dockerfile*
docker-compose*.yml
.dockerignore
# 文档和说明文件
README.md
*.md
cursorrules
# 批处理脚本和配置文件
*.bat
*.sh
# 测试文件
test/
tests/
__tests__/
*.test.js
*.spec.js
# 其他不需要的文件
.editorconfig
.browserslistrc
.prettierrc*
.eslintrc*
jest.config.js
babel.config.js
# 绩效计分系统 Docker 镜像
# 使用多阶段构建优化镜像大小
# 第一阶段:构建阶段
FROM node:18-alpine AS builder
# 设置工作目录
WORKDIR /app
# 复制package文件
COPY package*.json ./
# 安装依赖(包括开发依赖,用于构建)
RUN npm ci --silent
# 复制源代码
COPY . .
# 构建应用
RUN npm run build
# 第二阶段:生产阶段
FROM nginx:alpine AS production
# 安装必要的工具
RUN apk add --no-cache tzdata
# 设置时区为中国标准时间
ENV TZ=Asia/Shanghai
# 创建nginx用户和组(如果不存在)
RUN addgroup -g 101 -S nginx || true
RUN adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx || true
# 复制构建产物到nginx目录
COPY --from=builder /app/dist /usr/share/nginx/html
# 复制nginx配置文件
COPY nginx.conf /etc/nginx/nginx.conf
# 复制健康检查脚本
COPY docker-health-check.sh /usr/local/bin/health-check.sh
RUN chmod +x /usr/local/bin/health-check.sh
# 创建日志目录
RUN mkdir -p /var/log/nginx && \
chown -R nginx:nginx /var/log/nginx && \
chown -R nginx:nginx /usr/share/nginx/html
# 暴露端口
EXPOSE 80
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD /usr/local/bin/health-check.sh
# 启动nginx
CMD ["nginx", "-g", "daemon off;"]
# 绩效计分系统 - Docker 部署指南
# 绩效计分系统 - Docker 部署指南
## 📋 概述
本指南提供了绩效计分系统的Docker容器化部署方案,使用多阶段构建优化镜像大小,并通过nginx提供高性能的静态文件服务。
## 🛠️ 环境要求
### 系统要求
- Docker Engine 20.10.0 或更高版本
- Docker Compose 2.0.0 或更高版本
- 至少 2GB 可用内存
- 至少 1GB 可用磁盘空间
### 检查环境
```bash
# 检查Docker版本
docker --version
# 检查Docker Compose版本
docker-compose --version
# 检查Docker服务状态
docker info
```
## 🚀 快速启动
### 1. 使用 Docker Compose(推荐)
```bash
# 构建并启动服务
docker-compose up -d
# 查看服务状态
docker-compose ps
# 查看日志
docker-compose logs -f
```
### 2. 手动构建和运行
```bash
# 构建镜像
docker build -t performance-score-system:latest .
# 运行容器
docker run -d \
--name performance-score-frontend \
-p 4001:80 \
--restart unless-stopped \
performance-score-system:latest
```
## 🌐 访问应用
启动成功后,在浏览器中访问:
```
http://localhost:4001
```
### 默认登录账号
| 角色 | 用户名 | 密码 | 说明 |
|------|--------|------|------|
| 管理员 | admin | admin123 | 拥有所有权限 |
| 陈锐屏 | 13800138001 | 123456 | 负责机构 A、B、C、D、E |
| 张田田 | 13800138002 | 123456 | 负责机构 a、b、c、d、e |
| 余芳飞 | 13800138003 | 123456 | 负责机构 ①、②、③、④、⑤ |
## 📁 Docker 文件说明
### Dockerfile
- **多阶段构建**:第一阶段使用Node.js构建应用,第二阶段使用nginx提供服务
- **镜像优化**:最终镜像大小约30MB(基于nginx:alpine)
- **安全配置**:非root用户运行,健康检查支持
### docker-compose.yml
- **端口映射**:容器80端口映射到主机4001端口
- **环境变量**:时区设置为Asia/Shanghai
- **数据卷**:nginx日志持久化存储
- **网络配置**:独立的bridge网络
- **健康检查**:自动监控服务状态
### .dockerignore
- 排除不必要的文件和目录
- 减少构建上下文大小
- 提高构建速度
## 🔧 常用命令
### 服务管理
```bash
# 启动服务
docker-compose up -d
# 停止服务
docker-compose down
# 重启服务
docker-compose restart
# 查看服务状态
docker-compose ps
# 查看实时日志
docker-compose logs -f performance-score-frontend
```
### 镜像管理
```bash
# 重新构建镜像
docker-compose build --no-cache
# 拉取最新镜像
docker-compose pull
# 查看镜像
docker images | grep performance-score
# 删除镜像
docker rmi performance-score-system:latest
```
### 容器管理
```bash
# 进入容器
docker exec -it performance-score-frontend sh
# 查看容器资源使用
docker stats performance-score-frontend
# 查看容器详细信息
docker inspect performance-score-frontend
```
## 📊 监控和维护
### 健康检查
系统内置健康检查端点:
```bash
# 检查服务健康状态
curl http://localhost:4001/health
# 查看健康检查日志
docker-compose logs performance-score-frontend | grep health
```
### 日志管理
```bash
# 查看nginx访问日志
docker exec performance-score-frontend tail -f /var/log/nginx/access.log
# 查看nginx错误日志
docker exec performance-score-frontend tail -f /var/log/nginx/error.log
# 清理日志(谨慎操作)
docker exec performance-score-frontend sh -c "echo '' > /var/log/nginx/access.log"
```
### 数据备份
```bash
# 备份nginx日志
docker cp performance-score-frontend:/var/log/nginx ./nginx-logs-backup
# 备份容器配置
docker inspect performance-score-frontend > container-config-backup.json
```
## 🔒 安全配置
### 网络安全
- 使用独立的Docker网络
- 仅暴露必要的端口
- 配置适当的防火墙规则
### 容器安全
- 非root用户运行
- 只读文件系统(除日志目录)
- 资源限制配置
### nginx安全
- 安全头配置
- 文件上传大小限制
- 隐藏nginx版本信息
## 🚨 故障排除
### 常见问题
#### 1. 端口被占用
```bash
# 检查端口占用
netstat -tulpn | grep 4001
# 修改端口映射
# 编辑 docker-compose.yml 中的 ports 配置
```
#### 2. 构建失败
```bash
# 清理Docker缓存
docker system prune -a
# 重新构建
docker-compose build --no-cache
```
#### 3. 容器无法启动
```bash
# 查看详细错误信息
docker-compose logs performance-score-frontend
# 检查容器状态
docker ps -a
```
#### 4. 访问403错误
```bash
# 检查nginx配置
docker exec performance-score-frontend nginx -t
# 重新加载nginx配置
docker exec performance-score-frontend nginx -s reload
```
## 📈 性能优化
### 资源限制
在docker-compose.yml中添加资源限制:
```yaml
services:
performance-score-frontend:
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
```
### 缓存优化
- 静态资源缓存:1年
- HTML文件:无缓存
- Gzip压缩:启用
## 🔄 更新部署
### 滚动更新
```bash
# 拉取最新代码
git pull
# 重新构建并部署
docker-compose up -d --build
# 验证更新
curl http://localhost:4001/health
```
### 回滚操作
```bash
# 停止当前服务
docker-compose down
# 使用之前的镜像
docker run -d --name performance-score-frontend -p 4001:80 performance-score-system:previous
# 或者从备份恢复
docker load < performance-score-backup.tar
```
## 📞 技术支持
如果在部署过程中遇到问题,请:
1. 检查Docker和Docker Compose版本
2. 查看容器日志获取详细错误信息
3. 确认端口没有被其他服务占用
4. 检查系统资源是否充足
---
**注意**:本部署方案适用于开发和测试环境。生产环境部署请根据实际需求调整安全配置和性能参数。
version: '3.8'
services:
# 绩效计分系统前端服务 - 生产环境配置
performance-score-frontend:
build:
context: .
dockerfile: Dockerfile
target: production
image: performance-score-system:latest
container_name: performance-score-frontend-prod
restart: always
ports:
- "4001:80"
environment:
# 时区设置
- TZ=Asia/Shanghai
# Nginx环境变量
- NGINX_HOST=0.0.0.0
- NGINX_PORT=80
# 生产环境标识
- NODE_ENV=production
volumes:
# 日志卷挂载
- nginx-logs:/var/log/nginx
# 生产环境nginx配置
- ./nginx.prod.conf:/etc/nginx/nginx.conf:ro
networks:
- performance-score-network
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/health"]
interval: 15s
timeout: 5s
retries: 5
start_period: 30s
deploy:
resources:
limits:
cpus: '2.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 256M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
security_opt:
- no-new-privileges:true
read_only: true
tmpfs:
- /tmp:noexec,nosuid,size=100m
- /var/cache/nginx:noexec,nosuid,size=50m
- /var/run:noexec,nosuid,size=10m
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
labels:
- "com.docker.compose.service=performance-score-frontend"
- "com.docker.compose.project=performance-score-system"
- "environment=production"
# 网络配置
networks:
performance-score-network:
driver: bridge
name: performance-score-network-prod
ipam:
config:
- subnet: 172.20.0.0/16
# 数据卷配置
volumes:
nginx-logs:
driver: local
name: performance-score-nginx-logs-prod
driver_opts:
type: none
o: bind
device: /var/log/performance-score
version: '3.8'
services:
# 绩效计分系统前端服务
performance-score-frontend:
build:
context: .
dockerfile: Dockerfile
target: production
image: performance-score-system:latest
container_name: performance-score-frontend
restart: unless-stopped
ports:
- "4001:80"
environment:
# 时区设置
- TZ=Asia/Shanghai
# Nginx环境变量
- NGINX_HOST=localhost
- NGINX_PORT=80
volumes:
# 日志卷挂载
- nginx-logs:/var/log/nginx
# 如果需要自定义nginx配置,可以挂载配置文件
# - ./nginx.conf:/etc/nginx/nginx.conf:ro
networks:
- performance-score-network
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.25'
memory: 128M
security_opt:
- no-new-privileges:true
read_only: true
tmpfs:
- /tmp
- /var/cache/nginx
- /var/run
labels:
- "traefik.enable=true"
- "traefik.http.routers.performance-score.rule=Host(`localhost`)"
- "traefik.http.services.performance-score.loadbalancer.server.port=80"
- "com.docker.compose.service=performance-score-frontend"
- "com.docker.compose.project=performance-score-system"
# 网络配置
networks:
performance-score-network:
driver: bridge
name: performance-score-network
# 数据卷配置
volumes:
nginx-logs:
driver: local
name: performance-score-nginx-logs
#!/bin/sh
# 绩效计分系统 Docker 健康检查脚本
# 设置超时时间
TIMEOUT=5
# 检查nginx进程
if ! pgrep nginx > /dev/null; then
echo "ERROR: nginx process not running"
exit 1
fi
# 检查端口监听
if ! netstat -ln | grep -q ":80 "; then
echo "ERROR: nginx not listening on port 80"
exit 1
fi
# 检查健康端点
if ! wget --quiet --timeout=$TIMEOUT --tries=1 --spider http://localhost/health; then
echo "ERROR: health endpoint not responding"
exit 1
fi
# 检查主页面
if ! wget --quiet --timeout=$TIMEOUT --tries=1 --spider http://localhost/; then
echo "ERROR: main page not responding"
exit 1
fi
# 检查静态资源
if [ -f "/usr/share/nginx/html/index.html" ]; then
echo "OK: Static files present"
else
echo "ERROR: Static files missing"
exit 1
fi
echo "OK: All health checks passed"
exit 0
@echo off
chcp 65001 >nul
echo ========================================
echo 绩效计分系统 - Docker 监控面板
echo ========================================
echo.
:MENU
echo 请选择操作:
echo 1. 查看服务状态
echo 2. 查看实时日志
echo 3. 查看资源使用情况
echo 4. 查看健康状态
echo 5. 重启服务
echo 6. 停止服务
echo 7. 清理系统
echo 8. 退出
echo.
set /p choice=请输入选项 (1-8):
if "%choice%"=="1" goto STATUS
if "%choice%"=="2" goto LOGS
if "%choice%"=="3" goto STATS
if "%choice%"=="4" goto HEALTH
if "%choice%"=="5" goto RESTART
if "%choice%"=="6" goto STOP
if "%choice%"=="7" goto CLEANUP
if "%choice%"=="8" goto EXIT
echo 无效选项,请重新选择
echo.
goto MENU
:STATUS
echo.
echo 📊 服务状态:
docker-compose ps
echo.
echo 🐳 Docker 镜像:
docker images | findstr performance-score
echo.
echo 🌐 网络状态:
docker network ls | findstr performance-score
echo.
echo 💾 数据卷状态:
docker volume ls | findstr performance-score
echo.
pause
goto MENU
:LOGS
echo.
echo 📋 实时日志 (按 Ctrl+C 停止):
docker-compose logs -f --tail=50
echo.
pause
goto MENU
:STATS
echo.
echo 📈 资源使用情况:
docker stats performance-score-frontend --no-stream
echo.
echo 💽 磁盘使用:
docker system df
echo.
pause
goto MENU
:HEALTH
echo.
echo 🏥 健康检查:
docker inspect performance-score-frontend --format='{{.State.Health.Status}}'
echo.
echo 🔍 健康检查历史:
docker inspect performance-score-frontend --format='{{range .State.Health.Log}}{{.Start}} - {{.Output}}{{end}}'
echo.
echo 🌐 服务可访问性测试:
curl -s -o nul -w "HTTP状态码: %%{http_code}\n响应时间: %%{time_total}s\n" http://localhost:4001/health
echo.
pause
goto MENU
:RESTART
echo.
echo 🔄 重启服务...
docker-compose restart
echo ✅ 服务重启完成
echo.
pause
goto MENU
:STOP
echo.
set /p confirm=确认停止服务? (y/N):
if /i "%confirm%"=="y" (
echo 🛑 停止服务...
docker-compose down
echo ✅ 服务已停止
) else (
echo 操作已取消
)
echo.
pause
goto MENU
:CLEANUP
echo.
echo ⚠️ 系统清理将删除未使用的镜像、容器和网络
set /p confirm=确认执行清理? (y/N):
if /i "%confirm%"=="y" (
echo 🧹 清理系统...
docker system prune -f
echo ✅ 清理完成
) else (
echo 操作已取消
)
echo.
pause
goto MENU
:EXIT
echo.
echo 👋 再见!
exit /b 0
@echo off
chcp 65001 >nul
echo ========================================
echo 绩效计分系统 - Docker 快速启动
echo ========================================
echo.
:: 检查Docker是否安装
docker --version >nul 2>&1
if %errorlevel% neq 0 (
echo ❌ Docker 未安装或未启动
echo 请先安装 Docker Desktop 并确保服务正在运行
echo 下载地址: https://www.docker.com/products/docker-desktop
pause
exit /b 1
)
:: 检查Docker Compose是否可用
docker-compose --version >nul 2>&1
if %errorlevel% neq 0 (
echo ❌ Docker Compose 不可用
echo 请确保 Docker Desktop 已正确安装
pause
exit /b 1
)
echo ✅ Docker 环境检查通过
echo.
:: 检查端口是否被占用
netstat -an | findstr ":4001" >nul 2>&1
if %errorlevel% equ 0 (
echo ⚠️ 端口 4001 已被占用
echo 请停止占用该端口的服务,或修改 docker-compose.yml 中的端口配置
pause
exit /b 1
)
echo ✅ 端口 4001 可用
echo.
echo 🚀 正在启动 Docker 容器...
echo 首次启动需要构建镜像,可能需要几分钟时间
echo.
:: 启动服务
docker-compose up -d --build
if %errorlevel% neq 0 (
echo ❌ Docker 容器启动失败
echo 请检查错误信息并重试
pause
exit /b 1
)
echo.
echo ✅ Docker 容器启动成功!
echo.
echo 📱 访问地址: http://localhost:4001
echo.
echo 🔐 默认登录账号:
echo - 管理员: admin / admin123
echo - 陈锐屏: 13800138001 / 123456
echo - 张田田: 13800138002 / 123456
echo - 余芳飞: 13800138003 / 123456
echo.
echo 📊 查看服务状态: docker-compose ps
echo 📋 查看日志: docker-compose logs -f
echo 🛑 停止服务: docker-compose down
echo.
:: 等待服务完全启动
echo 🔍 等待服务启动完成...
timeout /t 10 /nobreak >nul
:: 检查服务健康状态
curl -s http://localhost:4001/health >nul 2>&1
if %errorlevel% equ 0 (
echo ✅ 服务健康检查通过
echo.
echo 🎉 系统已就绪,可以开始使用!
) else (
echo ⚠️ 服务可能还在启动中,请稍等片刻后访问
)
echo.
echo 按任意键打开浏览器访问系统...
pause >nul
:: 打开浏览器
start http://localhost:4001
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
# 性能优化
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 10M;
# Gzip压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# 安全头
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# Vue.js 单页应用路由支持
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# API代理(如果需要)
location /api/ {
# 如果有后端API,可以在这里配置代理
# proxy_pass http://backend:3000;
# 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;
return 404;
}
# 健康检查端点
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
# 错误页面
error_page 404 /index.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
# 优化worker连接数
events {
worker_connections 2048;
use epoll;
multi_accept on;
worker_rlimit_nofile 4096;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$request_time $upstream_response_time';
access_log /var/log/nginx/access.log main;
# 性能优化
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 1000;
types_hash_max_size 2048;
client_max_body_size 10M;
client_body_buffer_size 128k;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
# 隐藏nginx版本
server_tokens off;
# Gzip压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml
application/x-font-ttf
application/vnd.ms-fontobject
font/opentype;
# Brotli压缩(如果支持)
# brotli on;
# brotli_comp_level 6;
# brotli_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# 安全头
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self';" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# 限制请求
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html index.htm;
# 访问日志
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
add_header Vary "Accept-Encoding";
try_files $uri =404;
# 预压缩文件支持
location ~* \.(js|css)$ {
gzip_static on;
}
}
# HTML文件缓存控制
location ~* \.(html|htm)$ {
expires -1;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# API限流
location /api/ {
limit_req zone=api burst=20 nodelay;
# 如果有后端API,可以在这里配置代理
return 404;
}
# 登录接口限流
location /login {
limit_req zone=login burst=5 nodelay;
try_files $uri $uri/ /index.html;
}
# Vue.js 单页应用路由支持
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# 健康检查端点
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
# 状态监控端点(仅内部访问)
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 172.16.0.0/12;
deny all;
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# 禁止访问备份文件
location ~* \.(bak|backup|old|orig|original|tmp)$ {
deny all;
access_log off;
log_not_found off;
}
# 错误页面
error_page 404 /index.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
......@@ -8,5 +8,31 @@ export default defineConfig({
alias: {
'@': '/src'
}
},
build: {
// 生产环境构建优化
minify: 'terser',
sourcemap: false,
rollupOptions: {
output: {
// 分包策略
manualChunks: {
vendor: ['vue', 'vue-router', 'pinia'],
elementPlus: ['element-plus', '@element-plus/icons-vue'],
utils: ['xlsx']
}
}
},
// 压缩配置
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
},
server: {
host: '0.0.0.0',
port: 5173
}
})
\ No newline at end of file
})
\ No newline at end of file
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