deploy: 本地部署完成 - Gunicorn + Nginx 配置

This commit is contained in:
maoshen
2026-04-10 13:48:16 +00:00
parent e342156e9f
commit b180ebd9f6
4 changed files with 92 additions and 0 deletions

80
city-manual/deploy.sh Normal file
View File

@@ -0,0 +1,80 @@
#!/bin/bash
# 城市手册 - 自动部署脚本
set -e
echo "🚀 开始部署城市手册项目..."
# 1. 安装依赖
echo "📦 安装 Python 依赖..."
cd /root/.openclaw/workspace/city-manual/backend
pip3 install -r requirements.txt --break-system-packages -q
# 2. 数据库迁移
echo "🗄️ 执行数据库迁移..."
python3 manage.py migrate --noinput
# 3. 收集静态文件
echo "📁 收集静态文件..."
python3 manage.py collectstatic --noinput
# 4. 创建 Gunicorn 服务
echo "⚙️ 创建 Gunicorn 服务..."
cat > /etc/systemd/system/city-manual.service << EOF
[Unit]
Description=City Manual Gunicorn Service
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/root/.openclaw/workspace/city-manual/backend
ExecStart=/usr/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/city-manual.sock city_manual.wsgi:application
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable city-manual
systemctl start city-manual
# 5. 配置 Nginx
echo "🌐 配置 Nginx..."
cat > /etc/nginx/sites-available/city-manual << 'EOF'
server {
listen 80;
server_name cssc.datalibstar.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /root/.openclaw/workspace/city-manual/backend/static/;
}
location /media/ {
alias /root/.openclaw/workspace/city-manual/backend/media/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/city-manual.sock;
}
}
EOF
ln -sf /etc/nginx/sites-available/city-manual /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
# 6. 导入示例数据
echo "📊 导入示例数据..."
python3 manage.py seed_data
echo ""
echo "✅ 部署完成!"
echo ""
echo "📍 访问地址http://cssc.datalibstar.com"
echo "📍 Admin: http://cssc.datalibstar.com/admin"
echo "📍 测试账号demo / demo123"