124 lines
2.9 KiB
Markdown
124 lines
2.9 KiB
Markdown
|
|
# 管理端部署说明
|
|||
|
|
|
|||
|
|
## 环境配置
|
|||
|
|
|
|||
|
|
已将生产环境 API 地址修改为:`http://115.190.167.176:20002`
|
|||
|
|
|
|||
|
|
## 部署步骤
|
|||
|
|
|
|||
|
|
### 1. 本地构建
|
|||
|
|
|
|||
|
|
在管理端目录执行:
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd e:\ai-clone\ai-clone\admin
|
|||
|
|
npm run build
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
构建完成后,会在 `dist` 目录生成静态文件。
|
|||
|
|
|
|||
|
|
### 2. 上传到服务器
|
|||
|
|
|
|||
|
|
将 `dist` 目录下的所有文件上传到服务器的网站目录:
|
|||
|
|
- 宝塔面板路径:`/www/wwwroot/fh.admin-ai.cloud`
|
|||
|
|
|
|||
|
|
### 3. 宝塔面板配置
|
|||
|
|
|
|||
|
|
#### 3.1 创建网站
|
|||
|
|
1. 在宝塔面板 -> 网站 -> 添加站点
|
|||
|
|
2. 域名填写:`fh.admin-ai.cloud` 或 `115.190.167.176`
|
|||
|
|
3. 根目录:`/www/wwwroot/fh.admin-ai.cloud`
|
|||
|
|
4. PHP版本:纯静态(不需要PHP)
|
|||
|
|
|
|||
|
|
#### 3.2 配置 Nginx
|
|||
|
|
|
|||
|
|
在网站设置 -> 配置文件中,添加以下配置:
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
server {
|
|||
|
|
listen 20002;
|
|||
|
|
server_name fh.admin-ai.cloud 115.190.167.176;
|
|||
|
|
|
|||
|
|
root /www/wwwroot/fh.admin-ai.cloud;
|
|||
|
|
index index.html;
|
|||
|
|
|
|||
|
|
# 启用 gzip 压缩
|
|||
|
|
gzip on;
|
|||
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
|||
|
|
|
|||
|
|
# SPA 路由配置
|
|||
|
|
location / {
|
|||
|
|
try_files $uri $uri/ /index.html;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# API 代理(可选,如果需要通过同域名访问后端)
|
|||
|
|
location /api {
|
|||
|
|
proxy_pass http://127.0.0.1:20002;
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 静态资源缓存
|
|||
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|||
|
|
expires 1y;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### 3.3 开放端口
|
|||
|
|
|
|||
|
|
在宝塔面板 -> 安全 -> 添加端口规则:
|
|||
|
|
- 端口:`20002`
|
|||
|
|
- 协议:`TCP`
|
|||
|
|
- 备注:`管理端前端`
|
|||
|
|
|
|||
|
|
同时在服务器防火墙(阿里云/腾讯云安全组)中开放 20002 端口。
|
|||
|
|
|
|||
|
|
### 4. 重启 Nginx
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
nginx -t # 测试配置
|
|||
|
|
nginx -s reload # 重新加载配置
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
或在宝塔面板中重启 Nginx。
|
|||
|
|
|
|||
|
|
### 5. 访问测试
|
|||
|
|
|
|||
|
|
访问以下地址测试:
|
|||
|
|
- http://fh.admin-ai.cloud:20002
|
|||
|
|
- http://115.190.167.176:20002
|
|||
|
|
|
|||
|
|
## 域名配置(可选)
|
|||
|
|
|
|||
|
|
如果要使用域名 `fh.admin-ai.cloud` 访问:
|
|||
|
|
|
|||
|
|
1. 在域名服务商处添加 A 记录:
|
|||
|
|
- 主机记录:`fh.admin-ai`
|
|||
|
|
- 记录类型:`A`
|
|||
|
|
- 记录值:`115.190.167.176`
|
|||
|
|
- TTL:默认
|
|||
|
|
|
|||
|
|
2. 等待 DNS 解析生效(通常几分钟到几小时)
|
|||
|
|
|
|||
|
|
## 后端 API 配置
|
|||
|
|
|
|||
|
|
确保后端服务运行在 `20002` 端口,或修改 `.env.production` 中的 `VITE_API_BASE` 为实际的后端地址。
|
|||
|
|
|
|||
|
|
## 常见问题
|
|||
|
|
|
|||
|
|
### 1. 页面刷新 404
|
|||
|
|
确保 Nginx 配置了 `try_files $uri $uri/ /index.html;`
|
|||
|
|
|
|||
|
|
### 2. API 请求失败
|
|||
|
|
检查:
|
|||
|
|
- 后端服务是否运行
|
|||
|
|
- 端口是否开放
|
|||
|
|
- CORS 跨域配置是否正确
|
|||
|
|
|
|||
|
|
### 3. 静态资源加载失败
|
|||
|
|
检查 `vite.config.ts` 中的 `base` 配置,确保路径正确。
|