feat: Produktions-Deployment mit Nginx und SSL

- 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
This commit is contained in:
2025-10-01 21:13:49 +02:00
parent 1d97e05000
commit 58fb163bbc
5 changed files with 716 additions and 0 deletions

113
scripts/setup-ssl.ps1 Normal file
View File

@@ -0,0 +1,113 @@
# 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
}

110
scripts/setup-ssl.sh Normal file
View File

@@ -0,0 +1,110 @@
#!/bin/bash
# SSL-Setup-Script für Stargirlnails Kiel
# Erstellt Let's Encrypt-Zertifikate und startet die Produktionsumgebung
set -e
# Farben für Output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}🔧 Stargirlnails Kiel - SSL-Setup${NC}"
echo "=================================="
# Prüfe ob .env-Datei existiert
if [ ! -f .env ]; then
echo -e "${RED}❌ .env-Datei nicht gefunden!${NC}"
echo "Bitte erstelle eine .env-Datei mit DOMAIN und ADMIN_EMAIL"
exit 1
fi
# Lade Umgebungsvariablen
source .env
# Prüfe erforderliche Variablen
if [ -z "$DOMAIN" ]; then
echo -e "${RED}❌ DOMAIN nicht in .env definiert!${NC}"
exit 1
fi
if [ -z "$ADMIN_EMAIL" ]; then
echo -e "${RED}❌ ADMIN_EMAIL nicht in .env definiert!${NC}"
exit 1
fi
echo -e "${GREEN}✅ Domain: $DOMAIN${NC}"
echo -e "${GREEN}✅ Admin E-Mail: $ADMIN_EMAIL${NC}"
echo ""
# Erstelle nginx.conf mit korrekter Domain
echo -e "${YELLOW}📝 Erstelle Nginx-Konfiguration...${NC}"
sed "s/\${DOMAIN}/$DOMAIN/g" nginx/nginx.conf > nginx/nginx.conf.tmp
mv nginx/nginx.conf.tmp nginx/nginx.conf
# Erstelle Docker Volumes
echo -e "${YELLOW}📦 Erstelle Docker Volumes...${NC}"
docker volume create certbot-certs 2>/dev/null || true
docker volume create certbot-webroot 2>/dev/null || true
# Starte temporären HTTP-Server für Domain-Validierung
echo -e "${YELLOW}🌐 Starte temporären HTTP-Server...${NC}"
docker-compose -f docker-compose-prod.yml up -d nginx
# Warte bis Nginx läuft
echo -e "${YELLOW}⏳ Warte auf Nginx...${NC}"
sleep 10
# Erstelle SSL-Zertifikat
echo -e "${YELLOW}🔐 Erstelle SSL-Zertifikat für $DOMAIN...${NC}"
docker-compose -f docker-compose-prod.yml run --rm certbot certbot certonly \
--webroot \
--webroot-path=/var/www/certbot \
--email $ADMIN_EMAIL \
--agree-tos \
--no-eff-email \
--force-renewal \
-d $DOMAIN
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ SSL-Zertifikat erfolgreich erstellt!${NC}"
else
echo -e "${RED}❌ SSL-Zertifikat-Erstellung fehlgeschlagen!${NC}"
echo "Mögliche Ursachen:"
echo "- Domain ist nicht erreichbar"
echo "- Port 80 ist blockiert"
echo "- DNS-Einträge sind nicht korrekt"
exit 1
fi
# Starte alle Services
echo -e "${YELLOW}🚀 Starte alle Services...${NC}"
docker-compose -f docker-compose-prod.yml up -d
# Prüfe Status
echo -e "${YELLOW}🔍 Prüfe Service-Status...${NC}"
sleep 5
if docker-compose -f docker-compose-prod.yml ps | grep -q "Up"; then
echo -e "${GREEN}✅ Alle Services laufen!${NC}"
echo ""
echo -e "${BLUE}🌐 Deine Anwendung ist jetzt verfügbar unter:${NC}"
echo -e "${GREEN} https://$DOMAIN${NC}"
echo ""
echo -e "${BLUE}📋 Nützliche Befehle:${NC}"
echo " Status anzeigen: docker-compose -f docker-compose-prod.yml ps"
echo " Logs anzeigen: docker-compose -f docker-compose-prod.yml logs -f"
echo " Services stoppen: docker-compose -f docker-compose-prod.yml down"
echo " Zertifikat erneuern: docker-compose -f docker-compose-prod.yml run --rm certbot certbot renew"
echo ""
echo -e "${YELLOW}⚠️ Wichtig:${NC}"
echo " - SSL-Zertifikate werden automatisch alle 12 Stunden erneuert"
echo " - Überwache die Logs regelmäßig"
echo " - Stelle sicher, dass Port 80 und 443 erreichbar sind"
else
echo -e "${RED}❌ Einige Services sind nicht gestartet!${NC}"
echo "Prüfe die Logs: docker-compose -f docker-compose-prod.yml logs"
exit 1
fi