# 部署文档 > 当前部署环境: doorcome.cn (Debian 12) ## 服务器要求 | 组件 | 版本 | 用途 | |------|------|------| | Python | 3.11+ | Django + Celery | | MySQL/MariaDB | 10.11+ | 数据存储 | | Redis | 6+ | Celery Broker | | Nginx | — | 反向代理 | | Node.js | 18+ | 前端 | ## 目录结构 ``` /home/simon/myquant/django/podcast/ # 后端代码 ├── venv/ # Python 虚拟环境 ├── staticfiles/ # Django 静态文件 ├── data/audios/ # 音频文件 ├── logs/ # 日志 └── frontend/ # 前端代码 └── .next/ # 前端构建产物 ``` ## systemd 服务 | 服务 | 端口 | 说明 | |------|------|------| | `podcast-gunicorn` | 8001 | Django API | | `podcast-celery` | — | AI 处理 Worker | | `podcast-frontend` | 3000 | Next.js 前端 | ### 管理命令 ```bash sudo systemctl status podcast-gunicorn sudo systemctl restart podcast-celery sudo journalctl -u podcast-frontend -n 50 -f ``` ## Nginx 路由 | 路径 | 后端 | |------|------| | `/api/` | `127.0.0.1:8001` (Django) | | `/admin/` | `127.0.0.1:8001` (Django) | | `/static/` | Django 静态文件 | | `/media/` | 音频文件 | | `/podcast/` | `127.0.0.1:3000` (Next.js) | ## 首次部署 ```bash # 1. 同步代码 rsync -avz --delete --exclude='node_modules' --exclude='__pycache__' \ --exclude='.env' --exclude='venv' --exclude='.next' \ ./ doorcome:/home/simon/myquant/django/podcast/ # 2. 安装依赖 ssh doorcome cd /home/simon/myquant/django/podcast source venv/bin/activate pip install -r requirements.txt # 3. 配置环境变量 vi .env # 填入数据库连接、API Key 等 # 4. 数据库迁移 python manage.py migrate python manage.py collectstatic --noinput python manage.py createsuperuser # 5. 启动服务 sudo systemctl start podcast-gunicorn sudo systemctl start podcast-celery sudo systemctl start podcast-frontend # 6. 配置 Nginx # 编辑 /etc/nginx/sites-enabled/default 添加反向代理配置 sudo nginx -t && sudo systemctl reload nginx ``` ## 更新部署 ```bash # 本地同步代码 rsync -avz --delete --exclude={node_modules,__pycache__,.env,venv,.next,db.sqlite3} \ ./ doorcome:/home/simon/myquant/django/podcast/ # 远程执行 ssh doorcome " cd /home/simon/myquant/django/podcast source venv/bin/activate pip install -r requirements.txt -q python manage.py migrate python manage.py collectstatic --noinput sudo systemctl restart podcast-gunicorn podcast-celery cd frontend npm install -q npm run build sudo systemctl restart podcast-frontend " ``` ## 配置项 参见 `/home/simon/myquant/django/podcast/.env`: | 配置项 | 说明 | |--------|------| | `DEBUG` | 生产环境设为 False | | `ALLOWED_HOSTS` | 允许的域名 | | `DB_*` | MySQL 连接信息 | | `REDIS_URL` | Redis 连接 | | `DASHSCOPE_API_KEY` | 千问 ASR API Key | | `DEEPSEEK_API_KEY` | DeepSeek API Key | | `DEV_MOCK_ASR` | 0=真实 ASR, 1=Mock(开发用) |