mottery/fix_nginx.sh

58 lines
1.3 KiB
Bash

#!/bin/bash
echo "🔧 快速修复nginx配置..."
# 1. 停止当前服务
echo "🛑 停止当前服务..."
sudo pkill -f uvicorn
sudo systemctl stop nginx
# 2. 构建前端
echo "📦 构建前端..."
cd frontend
npm run build
cd ..
# 3. 部署前端文件
echo "📁 部署前端文件..."
sudo mkdir -p /var/www/html
sudo cp -r frontend/dist/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
# 4. 应用nginx配置
echo "⚙️ 应用nginx配置..."
sudo cp nginx.conf /etc/nginx/sites-available/cp.mzh.one
sudo ln -sf /etc/nginx/sites-available/cp.mzh.one /etc/nginx/sites-enabled/
# 5. 启动nginx
echo "🚀 启动nginx..."
sudo nginx -t && sudo systemctl start nginx
# 6. 启动后端
echo "🚀 启动后端..."
cd backend
source venv/bin/activate
nohup uvicorn app.main:app --host 0.0.0.0 --port 8000 > backend.log 2>&1 &
cd ..
# 7. 检查服务状态
echo "⏳ 等待服务启动..."
sleep 3
echo "🔍 检查服务状态..."
if curl -f http://localhost:8000/health > /dev/null 2>&1; then
echo "✅ 后端服务正常"
else
echo "❌ 后端服务异常"
fi
if curl -f http://localhost/ > /dev/null 2>&1; then
echo "✅ nginx服务正常"
else
echo "❌ nginx服务异常"
fi
echo ""
echo "🎉 修复完成!"
echo "📋 访问地址: https://cp.mzh.one"