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.
This commit is contained in:
22
apache-http.conf.example
Normal file
22
apache-http.conf.example
Normal file
@@ -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
|
||||
<VirtualHost *:80>
|
||||
ServerName www.tt-tagebuch.de
|
||||
Redirect permanent / https://tt-tagebuch.de/
|
||||
</VirtualHost>
|
||||
|
||||
# HTTP: tt-tagebuch.de -> HTTPS: tt-tagebuch.de
|
||||
<VirtualHost *:80>
|
||||
ServerName tt-tagebuch.de
|
||||
Redirect permanent / https://tt-tagebuch.de/
|
||||
</VirtualHost>
|
||||
|
||||
60
apache-https.conf.example
Normal file
60
apache-https.conf.example
Normal file
@@ -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)
|
||||
<VirtualHost *:443>
|
||||
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/
|
||||
</VirtualHost>
|
||||
|
||||
# HTTPS: tt-tagebuch.de - Hauptkonfiguration (non-www)
|
||||
<VirtualHost *:443>
|
||||
ServerName tt-tagebuch.de
|
||||
|
||||
DocumentRoot /var/www/tt-tagebuch.de
|
||||
|
||||
<Directory /var/www/tt-tagebuch.de>
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
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/
|
||||
</VirtualHost>
|
||||
|
||||
@@ -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
|
||||
<VirtualHost *:80>
|
||||
ServerName www.tt-tagebuch.de
|
||||
Redirect permanent / https://tt-tagebuch.de/
|
||||
</VirtualHost>
|
||||
|
||||
# HTTP: tt-tagebuch.de -> HTTPS: tt-tagebuch.de
|
||||
<VirtualHost *:80>
|
||||
ServerName tt-tagebuch.de
|
||||
Redirect permanent / https://tt-tagebuch.de/
|
||||
</VirtualHost>
|
||||
|
||||
# 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)
|
||||
<VirtualHost *:443>
|
||||
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/
|
||||
</VirtualHost>
|
||||
|
||||
# ============================================
|
||||
# HTTPS (Port 443) - Hauptkonfiguration (non-www)
|
||||
# ============================================
|
||||
|
||||
<VirtualHost *:443>
|
||||
ServerName tt-tagebuch.de
|
||||
|
||||
@@ -61,4 +87,3 @@
|
||||
ProxyPass / http://localhost:3050/
|
||||
ProxyPassReverse / http://localhost:3050/
|
||||
</VirtualHost>
|
||||
|
||||
|
||||
72
update-apache-config.sh
Executable file
72
update-apache-config.sh
Executable file
@@ -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
|
||||
Reference in New Issue
Block a user