修改了vite配置

main
mula.liu 2025-12-23 18:12:15 +08:00
parent 945aab0635
commit 1ab6de4912
4 changed files with 33 additions and 6 deletions

View File

@ -28,8 +28,11 @@ BACKEND_PORT=8000
FRONTEND_PORT=8080 FRONTEND_PORT=8080
# ==================== 前端配置 ==================== # ==================== 前端配置 ====================
# API 基础 URL根据实际部署地址修改 # API 基础 URL根据实际部署方式选择
VITE_API_BASE_URL=http://localhost:8000 # 方式1推荐使用 Nginx 反向代理,前后端同域名同端口
VITE_API_BASE_URL=/api
# 方式2直接访问后端端口需开放后端端口可能有跨域问题
# VITE_API_BASE_URL=http://yourdomain.com:8001
# ==================== 存储配置 ==================== # ==================== 存储配置 ====================
# 文件存储路径(宿主机路径,用于存储项目文档和上传文件) # 文件存储路径(宿主机路径,用于存储项目文档和上传文件)

View File

@ -54,8 +54,11 @@ ADMIN_USERNAME=admin
ADMIN_PASSWORD=Your_Secure_Password_123 ADMIN_PASSWORD=Your_Secure_Password_123
ADMIN_EMAIL=admin@yourdomain.com ADMIN_EMAIL=admin@yourdomain.com
# API 地址(根据实际域名修改) # API 地址配置
VITE_API_BASE_URL=http://yourdomain.com:8000 # 推荐:使用 Nginx 反向代理(前后端同域名同端口,无跨域问题)
VITE_API_BASE_URL=/api
# 或:直接访问后端端口(需开放后端端口到外网)
# VITE_API_BASE_URL=http://yourdomain.com:8001
``` ```
**⚠️ 重要提示:** **⚠️ 重要提示:**
@ -63,6 +66,9 @@ VITE_API_BASE_URL=http://yourdomain.com:8000
- 生产环境必须修改所有默认密码 - 生产环境必须修改所有默认密码
- `DEBUG` 设置为 `false` - `DEBUG` 设置为 `false`
- `STORAGE_PATH` 可配置为绝对路径,便于数据管理和备份 - `STORAGE_PATH` 可配置为绝对路径,便于数据管理和备份
- **API 访问配置**
- 使用 `VITE_API_BASE_URL=/api` 时,前端通过 Nginx 反向代理访问后端,无需开放后端端口
- 使用 `VITE_API_BASE_URL=http://IP:8001` 时,直接访问后端,需要开放 8001 端口
## 📋 部署脚本使用 ## 📋 部署脚本使用

View File

@ -20,7 +20,6 @@ services:
command: command:
- --character-set-server=utf8mb4 - --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci - --collation-server=utf8mb4_unicode_ci
- --default-authentication-plugin=mysql_native_password
healthcheck: healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-root_password_change_me}"] test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-root_password_change_me}"]
interval: 10s interval: 10s

View File

@ -11,6 +11,25 @@ server {
gzip_min_length 1024; gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml+rss; gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml+rss;
# API 反向代理(代理到后端服务)
location /api/ {
proxy_pass http://backend:8000/;
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;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# WebSocket 支持
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# 前端路由支持 # 前端路由支持
location / { location / {
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;