diff --git a/apache-http.conf.example b/apache-http.conf.example new file mode 100644 index 0000000..52b000f --- /dev/null +++ b/apache-http.conf.example @@ -0,0 +1,22 @@ +# Apache-Konfiguration für tt-tagebuch.de - HTTP (Port 80) +# +# Diese Datei kopieren nach: /etc/apache2/sites-available/tt-tagebuch.de.conf +# Dann aktivieren mit: sudo a2ensite tt-tagebuch.de.conf +# Und neu starten: sudo systemctl restart apache2 +# +# WICHTIG: Folgende Module müssen aktiviert sein: +# sudo a2enmod rewrite +# sudo systemctl restart apache2 + +# HTTP: www.tt-tagebuch.de -> HTTPS: tt-tagebuch.de + + ServerName www.tt-tagebuch.de + Redirect permanent / https://tt-tagebuch.de/ + + +# HTTP: tt-tagebuch.de -> HTTPS: tt-tagebuch.de + + ServerName tt-tagebuch.de + Redirect permanent / https://tt-tagebuch.de/ + + diff --git a/apache-https.conf.example b/apache-https.conf.example new file mode 100644 index 0000000..32ec21e --- /dev/null +++ b/apache-https.conf.example @@ -0,0 +1,60 @@ +# Apache-Konfiguration für tt-tagebuch.de - HTTPS (Port 443) +# +# Diese Datei kopieren nach: /etc/apache2/sites-available/tt-tagebuch.de-le-ssl.conf +# Dann aktivieren mit: sudo a2ensite tt-tagebuch.de-le-ssl.conf +# Und neu starten: sudo systemctl restart apache2 +# +# WICHTIG: Folgende Module müssen aktiviert sein: +# sudo a2enmod proxy +# sudo a2enmod proxy_http +# sudo a2enmod proxy_wstunnel +# sudo a2enmod rewrite +# sudo a2enmod headers +# sudo systemctl restart apache2 + +# HTTPS: www.tt-tagebuch.de -> HTTPS: tt-tagebuch.de (301-Weiterleitung) + + ServerName www.tt-tagebuch.de + + SSLEngine on + SSLCertificateFile /etc/letsencrypt/live/tt-tagebuch.de/fullchain.pem + SSLCertificateKeyFile /etc/letsencrypt/live/tt-tagebuch.de/privkey.pem + Include /etc/letsencrypt/options-ssl-apache.conf + + Redirect permanent / https://tt-tagebuch.de/ + + +# HTTPS: tt-tagebuch.de - Hauptkonfiguration (non-www) + + ServerName tt-tagebuch.de + + DocumentRoot /var/www/tt-tagebuch.de + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/tt-tagebuch.de_error.log + CustomLog ${APACHE_LOG_DIR}/tt-tagebuch.de_access.log combined + + SSLEngine on + SSLCertificateFile /etc/letsencrypt/live/tt-tagebuch.de/fullchain.pem + SSLCertificateKeyFile /etc/letsencrypt/live/tt-tagebuch.de/privkey.pem + Include /etc/letsencrypt/options-ssl-apache.conf + + ProxyRequests Off + + # HINWEIS: Socket.IO läuft jetzt direkt auf HTTPS-Port 3051 (nicht über Apache-Proxy) + # Siehe backend/SOCKET_IO_SSL_SETUP.md für Details + + # API-Routen + ProxyPass /api http://localhost:3050/api + ProxyPassReverse /api http://localhost:3050/api + + # Alle anderen Anfragen an den Backend-Server (für Frontend) + ProxyPass / http://localhost:3050/ + ProxyPassReverse / http://localhost:3050/ + + diff --git a/apache.conf.example b/apache.conf.example index ba753ca..61258db 100644 --- a/apache.conf.example +++ b/apache.conf.example @@ -1,5 +1,16 @@ -# Apache-Konfiguration für tt-tagebuch.de mit WebSocket-Support +# Apache-Konfiguration für tt-tagebuch.de # +# HINWEIS: Diese Datei ist eine kombinierte Referenz. +# Für die tatsächliche Konfiguration werden zwei separate Dateien verwendet: +# +# 1. apache-http.conf.example -> /etc/apache2/sites-available/tt-tagebuch.de.conf +# (HTTP, Port 80 - Weiterleitung zu HTTPS) +# +# 2. apache-https.conf.example -> /etc/apache2/sites-available/tt-tagebuch.de-le-ssl.conf +# (HTTPS, Port 443 - Hauptkonfiguration) +# +# Oder verwende das Update-Skript: ./update-apache-config.sh +# # WICHTIG: Folgende Module müssen aktiviert sein: # sudo a2enmod proxy # sudo a2enmod proxy_http @@ -8,27 +19,42 @@ # sudo a2enmod headers # sudo systemctl restart apache2 -# 301-Weiterleitung von www auf non-www (HTTP) +# ============================================ +# HTTP (Port 80) - Weiterleitung zu HTTPS +# ============================================ + +# HTTP: www.tt-tagebuch.de -> HTTPS: tt-tagebuch.de ServerName www.tt-tagebuch.de Redirect permanent / https://tt-tagebuch.de/ +# HTTP: tt-tagebuch.de -> HTTPS: tt-tagebuch.de ServerName tt-tagebuch.de Redirect permanent / https://tt-tagebuch.de/ -# 301-Weiterleitung von www auf non-www (HTTPS) +# ============================================ +# HTTPS (Port 443) - Weiterleitung www -> non-www +# ============================================ + +# HTTPS: www.tt-tagebuch.de -> HTTPS: tt-tagebuch.de (301-Weiterleitung) ServerName www.tt-tagebuch.de + SSLEngine on SSLCertificateFile /etc/letsencrypt/live/tt-tagebuch.de/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/tt-tagebuch.de/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf + Redirect permanent / https://tt-tagebuch.de/ +# ============================================ +# HTTPS (Port 443) - Hauptkonfiguration (non-www) +# ============================================ + ServerName tt-tagebuch.de @@ -61,4 +87,3 @@ ProxyPass / http://localhost:3050/ ProxyPassReverse / http://localhost:3050/ - diff --git a/update-apache-config.sh b/update-apache-config.sh new file mode 100755 index 0000000..a31e910 --- /dev/null +++ b/update-apache-config.sh @@ -0,0 +1,72 @@ +#!/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