- docker-compose-prod.yml: Produktionsumgebung mit Nginx Reverse Proxy - nginx/nginx.conf: Optimierte Nginx-Konfiguration mit SSL und Sicherheits-Headers - Rate Limiting für API-Endpunkte (10/s) und Login (5/min) - Automatische SSL-Zertifikate via Let's Encrypt/Certbot - Gzip-Kompression und Performance-Optimierungen Setup-Scripts: - scripts/setup-ssl.sh: Bash-Script für Linux/macOS - scripts/setup-ssl.ps1: PowerShell-Script für Windows - Automatische Domain-Konfiguration aus .env (DOMAIN, ADMIN_EMAIL) - Ein-Klick-Setup für SSL-Zertifikate Dokumentation: - docs/production-deployment.md: Vollständige Deployment-Anleitung - Troubleshooting, Monitoring, Backup-Strategien - Sicherheitsempfehlungen und Best Practices Features: - Automatische SSL-Zertifikat-Erneuerung (alle 12h) - HSTS, CSP, XSS-Schutz - Health Checks und Monitoring - Persistente Daten über Docker Volumes
114 lines
4.4 KiB
PowerShell
114 lines
4.4 KiB
PowerShell
# PowerShell-Script für SSL-Setup auf Windows (Entwicklung)
|
|
# Für Produktionsumgebung verwende das Bash-Script auf Linux
|
|
|
|
param(
|
|
[string]$Domain = "",
|
|
[string]$AdminEmail = ""
|
|
)
|
|
|
|
Write-Host "🔧 Stargirlnails Kiel - SSL-Setup (Windows)" -ForegroundColor Blue
|
|
Write-Host "============================================="
|
|
|
|
# Prüfe ob .env-Datei existiert
|
|
if (-not (Test-Path ".env")) {
|
|
Write-Host "❌ .env-Datei nicht gefunden!" -ForegroundColor Red
|
|
Write-Host "Bitte erstelle eine .env-Datei mit DOMAIN und ADMIN_EMAIL"
|
|
exit 1
|
|
}
|
|
|
|
# Lade .env-Datei
|
|
$envContent = Get-Content ".env"
|
|
$envVars = @{}
|
|
foreach ($line in $envContent) {
|
|
if ($line -match "^([^#][^=]+)=(.*)$") {
|
|
$envVars[$matches[1]] = $matches[2]
|
|
}
|
|
}
|
|
|
|
# Verwende Parameter oder .env-Werte
|
|
if ($Domain) { $envVars["DOMAIN"] = $Domain }
|
|
if ($AdminEmail) { $envVars["ADMIN_EMAIL"] = $AdminEmail }
|
|
|
|
# Prüfe erforderliche Variablen
|
|
if (-not $envVars["DOMAIN"]) {
|
|
Write-Host "❌ DOMAIN nicht definiert!" -ForegroundColor Red
|
|
Write-Host "Verwende: .\setup-ssl.ps1 -Domain 'example.com' -AdminEmail 'admin@example.com'"
|
|
exit 1
|
|
}
|
|
|
|
if (-not $envVars["ADMIN_EMAIL"]) {
|
|
Write-Host "❌ ADMIN_EMAIL nicht definiert!" -ForegroundColor Red
|
|
Write-Host "Verwende: .\setup-ssl.ps1 -Domain 'example.com' -AdminEmail 'admin@example.com'"
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "✅ Domain: $($envVars['DOMAIN'])" -ForegroundColor Green
|
|
Write-Host "✅ Admin E-Mail: $($envVars['ADMIN_EMAIL'])" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Erstelle nginx.conf mit korrekter Domain
|
|
Write-Host "📝 Erstelle Nginx-Konfiguration..." -ForegroundColor Yellow
|
|
$nginxConfig = Get-Content "nginx/nginx.conf" -Raw
|
|
$nginxConfig = $nginxConfig -replace '\$\{DOMAIN\}', $envVars["DOMAIN"]
|
|
Set-Content "nginx/nginx.conf" $nginxConfig
|
|
|
|
# Erstelle Docker Volumes
|
|
Write-Host "📦 Erstelle Docker Volumes..." -ForegroundColor Yellow
|
|
docker volume create certbot-certs 2>$null
|
|
docker volume create certbot-webroot 2>$null
|
|
|
|
# Starte temporären HTTP-Server
|
|
Write-Host "🌐 Starte temporären HTTP-Server..." -ForegroundColor Yellow
|
|
docker-compose -f docker-compose-prod.yml up -d nginx
|
|
|
|
# Warte auf Nginx
|
|
Write-Host "⏳ Warte auf Nginx..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 10
|
|
|
|
# Erstelle SSL-Zertifikat
|
|
Write-Host "🔐 Erstelle SSL-Zertifikat für $($envVars['DOMAIN'])..." -ForegroundColor Yellow
|
|
$certbotCmd = "docker-compose -f docker-compose-prod.yml run --rm certbot certbot certonly --webroot --webroot-path=/var/www/certbot --email $($envVars['ADMIN_EMAIL']) --agree-tos --no-eff-email --force-renewal -d $($envVars['DOMAIN'])"
|
|
Invoke-Expression $certbotCmd
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "✅ SSL-Zertifikat erfolgreich erstellt!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "❌ SSL-Zertifikat-Erstellung fehlgeschlagen!" -ForegroundColor Red
|
|
Write-Host "Mögliche Ursachen:"
|
|
Write-Host "- Domain ist nicht erreichbar"
|
|
Write-Host "- Port 80 ist blockiert"
|
|
Write-Host "- DNS-Einträge sind nicht korrekt"
|
|
exit 1
|
|
}
|
|
|
|
# Starte alle Services
|
|
Write-Host "🚀 Starte alle Services..." -ForegroundColor Yellow
|
|
docker-compose -f docker-compose-prod.yml up -d
|
|
|
|
# Prüfe Status
|
|
Write-Host "🔍 Prüfe Service-Status..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 5
|
|
|
|
$services = docker-compose -f docker-compose-prod.yml ps
|
|
if ($services -match "Up") {
|
|
Write-Host "✅ Alle Services laufen!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "🌐 Deine Anwendung ist jetzt verfügbar unter:" -ForegroundColor Blue
|
|
Write-Host " https://$($envVars['DOMAIN'])" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "📋 Nützliche Befehle:" -ForegroundColor Blue
|
|
Write-Host " Status anzeigen: docker-compose -f docker-compose-prod.yml ps"
|
|
Write-Host " Logs anzeigen: docker-compose -f docker-compose-prod.yml logs -f"
|
|
Write-Host " Services stoppen: docker-compose -f docker-compose-prod.yml down"
|
|
Write-Host " Zertifikat erneuern: docker-compose -f docker-compose-prod.yml run --rm certbot certbot renew"
|
|
Write-Host ""
|
|
Write-Host "⚠️ Wichtig:" -ForegroundColor Yellow
|
|
Write-Host " - SSL-Zertifikate werden automatisch alle 12 Stunden erneuert"
|
|
Write-Host " - Überwache die Logs regelmäßig"
|
|
Write-Host " - Stelle sicher, dass Port 80 und 443 erreichbar sind"
|
|
} else {
|
|
Write-Host "❌ Einige Services sind nicht gestartet!" -ForegroundColor Red
|
|
Write-Host "Prüfe die Logs: docker-compose -f docker-compose-prod.yml logs"
|
|
exit 1
|
|
}
|