- 添加 Nginx 反向代理配置(支持 ngrok 域名) - 创建统一的 API 工具函数(自动适配域名) - 更新前端 API 配置支持相对路径 - 配置支付宝回调地址使用 ngrok URL - 优化 Docker Compose 配置(仅暴露 80 端口) - 添加完整的部署和配置文档
79 lines
2.3 KiB
PowerShell
79 lines
2.3 KiB
PowerShell
# Nginx 反向代理部署脚本 (PowerShell)
|
|
|
|
Write-Host "🚀 开始部署 AIGC 平台..." -ForegroundColor Green
|
|
|
|
# 检查 Docker
|
|
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
|
|
Write-Host "❌ Docker 未安装,请先安装 Docker" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
if (-not (Get-Command docker-compose -ErrorAction SilentlyContinue)) {
|
|
Write-Host "❌ Docker Compose 未安装,请先安装 Docker Compose" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 构建前端
|
|
Write-Host "📦 构建前端..." -ForegroundColor Yellow
|
|
Push-Location frontend
|
|
try {
|
|
npm install
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "❌ 前端依赖安装失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
npm run build
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "❌ 前端构建失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|
|
|
|
# 检查前端构建产物
|
|
if (-not (Test-Path "frontend/dist")) {
|
|
Write-Host "❌ 前端构建产物不存在,请检查构建过程" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "✅ 前端构建完成" -ForegroundColor Green
|
|
|
|
# 停止现有容器
|
|
Write-Host "🛑 停止现有容器..." -ForegroundColor Yellow
|
|
docker-compose down
|
|
|
|
# 构建并启动服务
|
|
Write-Host "🔨 构建并启动服务..." -ForegroundColor Yellow
|
|
docker-compose up -d --build
|
|
|
|
# 等待服务启动
|
|
Write-Host "⏳ 等待服务启动..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 10
|
|
|
|
# 检查服务状态
|
|
Write-Host "📊 检查服务状态..." -ForegroundColor Yellow
|
|
docker-compose ps
|
|
|
|
# 测试健康检查
|
|
Write-Host "🏥 测试健康检查..." -ForegroundColor Yellow
|
|
try {
|
|
$response = Invoke-WebRequest -Uri "http://localhost/health" -TimeoutSec 5 -UseBasicParsing
|
|
if ($response.StatusCode -eq 200) {
|
|
Write-Host "✅ Nginx 健康检查通过" -ForegroundColor Green
|
|
}
|
|
} catch {
|
|
Write-Host "⚠️ Nginx 健康检查失败" -ForegroundColor Yellow
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "✅ 部署完成!" -ForegroundColor Green
|
|
Write-Host "🌐 前端地址: http://localhost" -ForegroundColor Cyan
|
|
Write-Host "🔗 API 地址: http://localhost/api" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "查看日志: docker-compose logs -f" -ForegroundColor Gray
|
|
Write-Host "停止服务: docker-compose down" -ForegroundColor Gray
|
|
|