Files
trainingstagebuch/update-apache-config.sh
Torsten Schulz (local) 945fd85e39 Update Apache configuration example to clarify structure and enhance redirect handling
This commit revises the apache.conf.example file to provide clearer documentation on the configuration structure, emphasizing the separation of HTTP and HTTPS settings. It adds detailed comments regarding the use of separate configuration files for HTTP and HTTPS, and enhances the redirect rules for both www and non-www domains, ensuring proper traffic management and SEO practices.
2025-11-16 12:14:17 +01:00

73 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Skript zum Aktualisieren der Apache-Konfiguration für tt-tagebuch.de
# Führt automatisch ein Backup durch und aktualisiert beide Konfigurationsdateien
HTTP_CONFIG_FILE="/etc/apache2/sites-available/tt-tagebuch.de.conf"
HTTPS_CONFIG_FILE="/etc/apache2/sites-available/tt-tagebuch.de-le-ssl.conf"
HTTP_BACKUP_FILE="/etc/apache2/sites-available/tt-tagebuch.de.conf.backup.$(date +%Y%m%d_%H%M%S)"
HTTPS_BACKUP_FILE="/etc/apache2/sites-available/tt-tagebuch.de-le-ssl.conf.backup.$(date +%Y%m%d_%H%M%S)"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HTTP_EXAMPLE="${SCRIPT_DIR}/apache-http.conf.example"
HTTPS_EXAMPLE="${SCRIPT_DIR}/apache-https.conf.example"
echo "=== Apache-Konfiguration aktualisieren ==="
echo ""
# Backup und Update HTTP-Konfiguration
if [ -f "$HTTP_CONFIG_FILE" ]; then
echo "✓ Bestehende HTTP-Konfiguration gefunden: $HTTP_CONFIG_FILE"
echo " Erstelle Backup: $HTTP_BACKUP_FILE"
sudo cp "$HTTP_CONFIG_FILE" "$HTTP_BACKUP_FILE"
echo " ✓ Backup erstellt"
else
echo "⚠ HTTP-Konfigurationsdatei nicht gefunden: $HTTP_CONFIG_FILE"
echo " Erstelle neue Konfigurationsdatei"
fi
echo ""
echo "Aktualisiere HTTP-Konfiguration aus: $HTTP_EXAMPLE"
sudo cp "$HTTP_EXAMPLE" "$HTTP_CONFIG_FILE"
echo "✓ HTTP-Konfiguration aktualisiert"
# Backup und Update HTTPS-Konfiguration
if [ -f "$HTTPS_CONFIG_FILE" ]; then
echo ""
echo "✓ Bestehende HTTPS-Konfiguration gefunden: $HTTPS_CONFIG_FILE"
echo " Erstelle Backup: $HTTPS_BACKUP_FILE"
sudo cp "$HTTPS_CONFIG_FILE" "$HTTPS_BACKUP_FILE"
echo " ✓ Backup erstellt"
else
echo ""
echo "⚠ HTTPS-Konfigurationsdatei nicht gefunden: $HTTPS_CONFIG_FILE"
echo " Erstelle neue Konfigurationsdatei"
fi
echo ""
echo "Aktualisiere HTTPS-Konfiguration aus: $HTTPS_EXAMPLE"
sudo cp "$HTTPS_EXAMPLE" "$HTTPS_CONFIG_FILE"
echo "✓ HTTPS-Konfiguration aktualisiert"
# Prüfe Syntax
echo ""
echo "Prüfe Apache-Konfigurationssyntax..."
if sudo apache2ctl configtest; then
echo "✓ Syntax ist korrekt"
echo ""
echo "=== Nächste Schritte ==="
echo "1. Konfigurationen aktivieren (falls noch nicht aktiv):"
echo " sudo a2ensite tt-tagebuch.de.conf"
echo " sudo a2ensite tt-tagebuch.de-le-ssl.conf"
echo ""
echo "2. Apache neu starten:"
echo " sudo systemctl restart apache2"
echo ""
echo "3. Testen:"
echo " curl -I http://www.tt-tagebuch.de"
echo " curl -I http://tt-tagebuch.de"
echo " curl -I https://www.tt-tagebuch.de"
echo " (Alle sollten auf https://tt-tagebuch.de weiterleiten)"
else
echo "✗ Syntax-Fehler gefunden! Bitte manuell prüfen."
exit 1
fi