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:
110
scripts/setup-ssl.sh
Normal file
110
scripts/setup-ssl.sh
Normal 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
|
Reference in New Issue
Block a user