Files
vue-driven-cloud-storage/INSTALL_GUIDE.md
yuyx efaa2308eb feat: 全面优化代码质量至 8.55/10 分
## 安全增强
- 添加 CSRF 防护机制(Double Submit Cookie 模式)
- 增强密码强度验证(8字符+两种字符类型)
- 添加 Session 密钥安全检查
- 修复 .htaccess 文件上传漏洞
- 统一使用 getSafeErrorMessage() 保护敏感错误信息
- 增强数据库原型污染防护
- 添加被封禁用户分享访问检查

## 功能修复
- 修复模态框点击外部关闭功能
- 修复 share.html 未定义方法调用
- 修复 verify.html 和 reset-password.html API 路径
- 修复数据库 SFTP->OSS 迁移逻辑
- 修复 OSS 未配置时的错误提示
- 添加文件夹名称长度限制
- 添加文件列表 API 路径验证

## UI/UX 改进
- 添加 6 个按钮加载状态(登录/注册/修改密码等)
- 将 15+ 处 alert() 替换为 Toast 通知
- 添加防重复提交机制(创建文件夹/分享)
- 优化 loadUserProfile 防抖调用

## 代码质量
- 消除 formatFileSize 重复定义
- 集中模块导入到文件顶部
- 添加 JSDoc 注释
- 创建路由拆分示例 (routes/)

## 测试套件
- 添加 boundary-tests.js (60 用例)
- 添加 network-concurrent-tests.js (33 用例)
- 添加 state-consistency-tests.js (38 用例)
- 添加 test_share.js 和 test_admin.js

## 文档和配置
- 新增 INSTALL_GUIDE.md 手动部署指南
- 新增 VERSION.txt 版本历史
- 完善 .env.example 配置说明
- 新增 docker-compose.yml
- 完善 nginx.conf.example

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 10:45:51 +08:00

328 lines
6.0 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.
# 玩玩云 - 手动部署指南
本指南详细说明如何手动部署玩玩云系统。
## 环境要求
### 服务器要求
- **操作系统**: Linux (Ubuntu 18.04+ / Debian 10+ / CentOS 7+)
- **内存**: 最低 1GB RAM推荐 2GB+
- **磁盘空间**: 至少 2GB 可用空间
### 软件依赖
- **Node.js**: 20.x LTS
- **Nginx**: 1.18+
- **Git**: 2.x
## 部署步骤
### 1. 安装 Node.js 20.x
#### Ubuntu/Debian
```bash
# 安装 NodeSource 仓库
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
# 安装 Node.js
sudo apt-get install -y nodejs
# 验证安装
node -v # 应显示 v20.x.x
npm -v
```
#### CentOS/RHEL
```bash
# 安装 NodeSource 仓库
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
# 安装 Node.js
sudo yum install -y nodejs
# 验证安装
node -v
npm -v
```
### 2. 安装 Nginx
#### Ubuntu/Debian
```bash
sudo apt-get update
sudo apt-get install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
```
#### CentOS/RHEL
```bash
sudo yum install -y epel-release
sudo yum install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
```
### 3. 克隆项目
```bash
# 创建部署目录
sudo mkdir -p /var/www
cd /var/www
# 克隆项目
sudo git clone https://git.workyai.cn/237899745/vue-driven-cloud-storage.git wanwanyun
# 设置目录权限
sudo chown -R $USER:$USER /var/www/wanwanyun
```
### 4. 安装后端依赖
```bash
cd /var/www/wanwanyun/backend
# 安装依赖
npm install --production
# 创建数据目录
mkdir -p data storage
```
### 5. 配置环境变量
```bash
# 复制环境变量模板
cp .env.example .env
# 编辑配置文件
nano .env
```
**必须修改的配置**
```bash
# 生成随机 JWT 密钥
JWT_SECRET=$(node -e "console.log(require('crypto').randomBytes(32).toString('hex'))")
echo "JWT_SECRET=$JWT_SECRET"
# 修改管理员密码
ADMIN_PASSWORD=你的强密码
```
### 6. 配置 Nginx
```bash
# 复制 Nginx 配置
sudo cp /var/www/wanwanyun/nginx/nginx.conf /etc/nginx/sites-available/wanwanyun
# 修改配置中的路径
sudo sed -i 's|/usr/share/nginx/html|/var/www/wanwanyun/frontend|g' /etc/nginx/sites-available/wanwanyun
sudo sed -i 's|backend:40001|127.0.0.1:40001|g' /etc/nginx/sites-available/wanwanyun
# 创建软链接启用配置
sudo ln -sf /etc/nginx/sites-available/wanwanyun /etc/nginx/sites-enabled/
# 删除默认配置(可选)
sudo rm -f /etc/nginx/sites-enabled/default
# 测试配置
sudo nginx -t
# 重新加载 Nginx
sudo systemctl reload nginx
```
### 7. 配置系统服务
创建 systemd 服务文件:
```bash
sudo tee /etc/systemd/system/wanwanyun.service > /dev/null << 'EOF'
[Unit]
Description=WanWanYun Cloud Storage Service
After=network.target
[Service]
Type=simple
User=www-data
Group=www-data
WorkingDirectory=/var/www/wanwanyun/backend
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=10
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
EOF
```
设置目录权限:
```bash
sudo chown -R www-data:www-data /var/www/wanwanyun
```
启动服务:
```bash
sudo systemctl daemon-reload
sudo systemctl enable wanwanyun
sudo systemctl start wanwanyun
```
### 8. 验证部署
```bash
# 检查服务状态
sudo systemctl status wanwanyun
# 检查后端是否启动
curl http://127.0.0.1:40001/api/health
# 检查 Nginx 是否正常
curl http://localhost
```
## 配置 HTTPS推荐
### 使用 Let's Encrypt 免费证书
```bash
# 安装 Certbot
sudo apt-get install -y certbot python3-certbot-nginx
# 获取证书(替换为你的域名和邮箱)
sudo certbot --nginx -d your-domain.com --email your@email.com --agree-tos --non-interactive
# 验证自动续期
sudo certbot renew --dry-run
```
### 更新后端配置
获取证书后,编辑 `/var/www/wanwanyun/backend/.env`
```bash
ENFORCE_HTTPS=true
COOKIE_SECURE=true
TRUST_PROXY=1
```
重启服务:
```bash
sudo systemctl restart wanwanyun
```
## 防火墙配置
### UFW (Ubuntu)
```bash
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
```
### firewalld (CentOS)
```bash
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
```
## 日常维护
### 查看日志
```bash
# 查看服务日志
sudo journalctl -u wanwanyun -f
# 查看 Nginx 错误日志
sudo tail -f /var/log/nginx/error.log
```
### 更新系统
```bash
cd /var/www/wanwanyun
sudo git pull
cd backend && npm install --production
sudo systemctl restart wanwanyun
```
### 备份数据
```bash
# 备份数据库
sudo cp /var/www/wanwanyun/backend/data/database.db /backup/database.db.$(date +%Y%m%d)
# 备份上传文件(本地存储模式)
sudo tar -czf /backup/storage-$(date +%Y%m%d).tar.gz /var/www/wanwanyun/backend/storage/
```
## 故障排查
### 服务无法启动
```bash
# 检查日志
sudo journalctl -u wanwanyun -n 100
# 检查端口占用
sudo lsof -i :40001
# 检查 Node.js 版本
node -v
```
### 无法访问网页
```bash
# 检查 Nginx 状态
sudo systemctl status nginx
# 检查 Nginx 配置
sudo nginx -t
# 检查防火墙
sudo ufw status
```
### 数据库错误
```bash
# 检查数据库文件权限
ls -la /var/www/wanwanyun/backend/data/
# 修复权限
sudo chown -R www-data:www-data /var/www/wanwanyun/backend/data/
```
## 性能优化
### 启用 Nginx 缓存
在 Nginx 配置的 `location /` 中添加:
```nginx
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
```
### 配置日志轮转
```bash
sudo tee /etc/logrotate.d/wanwanyun > /dev/null << 'EOF'
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
EOF
```
## 相关链接
- [项目主页](https://git.workyai.cn/237899745/vue-driven-cloud-storage)
- [问题反馈](https://git.workyai.cn/237899745/vue-driven-cloud-storage/issues)
- [README](./README.md)