auto_trade_sys/backend/ENV_SETUP.md
薇薇安 4140370c2d a
2026-01-14 10:57:14 +08:00

58 lines
1.2 KiB
Markdown
Raw Permalink 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.

# 环境变量配置说明
## .env 文件配置
后端服务支持从 `.env` 文件读取配置,优先顺序:
1. `backend/.env` (优先)
2. 项目根目录 `.env`
3. 系统环境变量
## 创建 .env 文件
`backend/` 目录下创建 `.env` 文件:
```bash
cd backend
cp .env.example .env # 如果存在示例文件
# 或直接创建
touch .env
```
## 配置示例
编辑 `.env` 文件:
```bash
# 数据库配置
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=auto_trade_sys
# CORS配置多个用逗号分隔
CORS_ORIGINS=http://localhost:3000,http://localhost:5173
# 日志级别(可选)
LOG_LEVEL=INFO
```
## 验证配置
启动后端服务后,检查日志中是否有:
```
已加载环境变量文件: /path/to/backend/.env
```
如果没有看到这条日志,可能是:
1. `.env` 文件不存在
2. `python-dotenv` 未安装(运行 `pip install -r requirements.txt`
## 注意事项
1. **不要提交 .env 文件到 Git**(已在 .gitignore 中)
2. **生产环境**:建议使用系统环境变量或密钥管理服务
3. **密码安全**:确保 `.env` 文件权限正确(`chmod 600 .env`