102 lines
1.7 KiB
Markdown
102 lines
1.7 KiB
Markdown
# 部署文档
|
||
|
||
## 版本信息
|
||
|
||
- 版本: v1.0.0
|
||
- 最后更新: 2025-01-XX
|
||
- 维护者: 运维团队
|
||
|
||
## 部署前准备
|
||
|
||
### 1. 环境要求
|
||
|
||
- Python 3.8+
|
||
- 数据库(MySQL/PostgreSQL/SQLite)
|
||
- 反向代理(Nginx,可选)
|
||
|
||
### 2. 安装依赖
|
||
|
||
```bash
|
||
# 安装生产依赖
|
||
pip install -r requirements/base.txt
|
||
pip install -r requirements/production.txt
|
||
```
|
||
|
||
### 3. 配置环境变量
|
||
|
||
```bash
|
||
# 设置生产环境
|
||
export FLASK_ENV=production
|
||
|
||
# 配置必要的环境变量
|
||
# - SECRET_KEY
|
||
# - DATABASE_URL
|
||
# - CORS_ORIGINS
|
||
```
|
||
|
||
## 部署方式
|
||
|
||
### 方式1: 使用Gunicorn
|
||
|
||
```bash
|
||
# 使用配置文件
|
||
gunicorn -c gunicorn.conf.py "src.your_app:create_app()"
|
||
|
||
# 或直接指定参数
|
||
gunicorn --bind 0.0.0.0:5000 --workers 4 "src.your_app:create_app()"
|
||
```
|
||
|
||
### 方式2: 使用uWSGI
|
||
|
||
```bash
|
||
uwsgi --ini uwsgi.ini
|
||
```
|
||
|
||
### 方式3: 使用Docker
|
||
|
||
```bash
|
||
# 构建镜像
|
||
docker build -t your_app .
|
||
|
||
# 运行容器
|
||
docker run -d -p 5000:5000 --env-file .env your_app
|
||
```
|
||
|
||
## Nginx配置示例
|
||
|
||
```nginx
|
||
server {
|
||
listen 80;
|
||
server_name your_domain.com;
|
||
|
||
location / {
|
||
proxy_pass http://127.0.0.1:5000;
|
||
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;
|
||
}
|
||
}
|
||
```
|
||
|
||
## 监控和日志
|
||
|
||
### 日志位置
|
||
|
||
- 应用日志: `logs/app.log`
|
||
- Gunicorn访问日志: `logs/gunicorn_access.log`
|
||
- Gunicorn错误日志: `logs/gunicorn_error.log`
|
||
|
||
### 监控建议
|
||
|
||
- 使用Supervisor管理进程
|
||
- 配置日志轮转
|
||
- 设置健康检查端点
|
||
|
||
## 变更记录
|
||
|
||
### v1.0.0 (2025-01-XX)
|
||
- 初始版本
|
||
- 添加部署文档
|
||
|