v1.0.3 — 修复 gunicorn 多 worker session 丢失

- secret_key 从 os.urandom() 改为固定值/环境变量
- deploy.sh 首次部署自动生成 .env 并持久化
- 解决多 worker 下 session 解密失败导致保存 302
This commit is contained in:
mac
2026-06-02 23:40:14 +08:00
parent abdc1fc739
commit 668576b866
2 changed files with 14 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
#!/bin/bash
# ziwei-power 一键部署脚本
# 用法: bash deploy.sh [port]
#
# 首次运行: 自动生成 .env (SECRET_KEY),之后不变
# 多 worker 安全: 所有 worker 共享同一密钥
set -e
@@ -30,7 +33,15 @@ fi
echo "安装依赖..."
venv/bin/pip install -q -r requirements.txt
# 3. 自动建表(首次运行
# 3. 生成/读取固定 SECRET_KEY多 worker 共享
if [ ! -f ".env" ]; then
echo "生成 SECRET_KEY..."
python3 -c "import os; print('SECRET_KEY=' + os.urandom(24).hex())" > .env
fi
set -a; source .env; set +a
export SECRET_KEY
# 4. 自动建表(首次运行)
echo "初始化数据库..."
venv/bin/python -c "
from database import init_db