Files
zyt/admin/DEPLOYMENT_README.md
T
2026-03-13 14:08:52 +08:00

292 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 部署指南
## 快速开始
### 1. 本地开发环境
```bash
# 安装依赖
npm install
# 启动开发服务器
npm run dev
# 访问
http://localhost:5173
```
### 2. 生产环境打包
```bash
# 打包
npm run build
# 输出目录
dist/
# 文件会自动复制到
../server/public/admin/
```
## 部署步骤
### 步骤 1: 配置 HTTPS
TUIKit 视频通话功能需要 HTTPS 环境。
**快速配置(推荐):**
```bash
# 使用自动化脚本
sudo bash setup-https.sh
# 按照提示输入:
# - 项目路径
# - API 端口
```
**手动配置:**
参考 `HTTPS_DEPLOYMENT_GUIDE.md`
### 步骤 2: 配置 Nginx
使用提供的 `nginx-production.conf` 文件:
```bash
# 复制配置
sudo cp nginx-production.conf /etc/nginx/sites-available/admin
# 编辑配置(修改路径和端口)
sudo nano /etc/nginx/sites-available/admin
# 创建软链接
sudo ln -s /etc/nginx/sites-available/admin /etc/nginx/sites-enabled/
# 测试配置
sudo nginx -t
# 重启 Nginx
sudo systemctl restart nginx
```
### 步骤 3: 验证部署
```bash
# 检查 HTTPS 连接
curl -I https://api.zzzhengyangtang.cn/admin
# 检查证书
sudo certbot certificates
# 查看 Nginx 日志
sudo tail -f /var/log/nginx/admin_https_error.log
```
## 文件说明
| 文件 | 说明 |
|------|------|
| `nginx-production.conf` | Nginx HTTPS 配置文件 |
| `setup-https.sh` | 自动化 HTTPS 配置脚本 |
| `HTTPS_DEPLOYMENT_GUIDE.md` | 详细的 HTTPS 部署指南 |
| `TROUBLESHOOTING.md` | 故障排查指南 |
| `diagnose.js` | 浏览器诊断脚本 |
| `src/utils/checkHttps.ts` | HTTPS 检查工具 |
## 常见问题
### Q: 页面打不开
**A:**
1. 检查 Nginx 配置:`sudo nginx -t`
2. 查看错误日志:`sudo tail -f /var/log/nginx/error.log`
3. 确保静态文件路径正确
4. 清除浏览器缓存
### Q: TUIKit 错误
**A:**
1. 确保使用 HTTPS 协议
2. 检查浏览器控制台错误
3. 运行诊断脚本:`diagnose.js`
4. 查看 `TROUBLESHOOTING.md`
### Q: 视频通话无法连接
**A:**
1. 检查网络连接
2. 检查防火墙设置
3. 确保后端 API 正常运行
4. 检查签名获取是否成功
### Q: 证书过期
**A:**
```bash
# 手动续期
sudo certbot renew
# 检查自动续期任务
sudo crontab -l
```
## 性能优化
### 1. 启用 Gzip 压缩
`nginx-production.conf` 中添加:
```nginx
gzip on;
gzip_types text/plain text/css text/javascript application/javascript;
gzip_min_length 1000;
```
### 2. 启用浏览器缓存
已在 `nginx-production.conf` 中配置
### 3. 使用 CDN
修改 `vite.config.ts`
```typescript
export default defineConfig({
base: 'https://your-cdn.com/admin/',
// ...
})
```
### 4. 监控性能
在浏览器控制台运行 `diagnose.js` 查看性能指标
## 监控和维护
### 日志监控
```bash
# 实时查看 Nginx 访问日志
sudo tail -f /var/log/nginx/admin_https_access.log
# 查看错误日志
sudo tail -f /var/log/nginx/admin_https_error.log
# 查看应用日志
tail -f /path/to/your/app.log
```
### 证书监控
```bash
# 查看证书状态
sudo certbot certificates
# 检查证书有效期
openssl x509 -in /etc/letsencrypt/live/api.zzzhengyangtang.cn/fullchain.pem -noout -dates
# 测试自动续期
sudo certbot renew --dry-run
```
### 系统监控
```bash
# 检查磁盘空间
df -h
# 检查内存使用
free -h
# 检查 CPU 使用
top
# 检查进程
ps aux | grep nginx
```
## 安全建议
1. **启用 HSTS**(已配置)
- 强制使用 HTTPS
- 防止中间人攻击
2. **定期更新**
```bash
# 更新系统
sudo apt update && sudo apt upgrade
# 更新 Node.js 依赖
npm update
```
3. **备份重要文件**
```bash
# 备份 SSL 证书
sudo tar -czf ssl-backup.tar.gz /etc/letsencrypt/
# 备份应用文件
tar -czf app-backup.tar.gz /path/to/your/app/
```
4. **配置防火墙**
```bash
# 允许 HTTP 和 HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# 允许 SSH
sudo ufw allow 22/tcp
# 启用防火墙
sudo ufw enable
```
## 故障排查
### 问题:页面加载缓慢
**解决:**
1. 检查网络连接
2. 启用 Gzip 压缩
3. 使用 CDN
4. 优化资源大小
### 问题:内存占用过高
**解决:**
1. 检查浏览器扩展
2. 清除缓存
3. 重启浏览器
4. 检查应用内存泄漏
### 问题:连接超时
**解决:**
1. 检查网络连接
2. 增加超时时间
3. 检查防火墙
4. 检查后端服务
## 获取帮助
1. 查看 `TROUBLESHOOTING.md` 获取详细的故障排查指南
2. 运行 `diagnose.js` 诊断脚本
3. 查看 Nginx 和应用日志
4. 参考 TUIKit 官方文档:https://cloud.tencent.com/document/product/647
## 更新日志
### v1.0.0 (2024-03-12)
- ✓ 初始版本
- ✓ HTTPS 配置支持
- ✓ TUIKit 错误处理
- ✓ 诊断工具
- ✓ 部署指南
## 许可证
MIT