This commit adds comments to the Apache configuration file, highlighting that mod_proxy_http can directly handle WebSockets starting from Apache 2.4.47. It provides an alternative ProxyPass configuration for WebSocket connections, ensuring better compatibility and guidance for users facing issues with the existing RewriteRule setup.
82 lines
3.1 KiB
Plaintext
82 lines
3.1 KiB
Plaintext
# Apache-Konfiguration für tt-tagebuch.de mit WebSocket-Support
|
|
#
|
|
# 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
|
|
|
|
<VirtualHost *:443>
|
|
ServerName tt-tagebuch.de
|
|
ServerAlias www.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
|
|
|
|
# WebSocket-Proxy für Socket.IO
|
|
# WICHTIG: Diese LocationMatch muss VOR den anderen ProxyPass-Direktiven stehen
|
|
# WICHTIG: mod_proxy_wstunnel muss aktiviert sein (sudo a2enmod proxy_wstunnel)
|
|
# WICHTIG: mod_rewrite muss aktiviert sein (sudo a2enmod rewrite)
|
|
#
|
|
# HINWEIS: Seit Apache 2.4.47 kann mod_proxy_http WebSockets direkt verarbeiten.
|
|
# Falls die RewriteRule nicht funktioniert, verwende die alternative Konfiguration unten.
|
|
|
|
# WebSocket-Upgrade erkennen und weiterleiten (wss:// -> ws://)
|
|
# Verwende RewriteRule, um WebSocket-Upgrades zu erkennen und weiterzuleiten
|
|
<LocationMatch "^/socket\.io/">
|
|
RewriteEngine on
|
|
RewriteCond %{HTTP:Upgrade} websocket [NC]
|
|
RewriteCond %{HTTP:Connection} upgrade [NC]
|
|
RewriteRule ^/socket\.io/?(.*) ws://localhost:3050/socket.io/$1 [P,L,QSA]
|
|
|
|
# Fallback für HTTP-Polling (wird verwendet, wenn RewriteRule nicht greift)
|
|
ProxyPass http://localhost:3050/socket.io/
|
|
ProxyPassReverse http://localhost:3050/socket.io/
|
|
|
|
ProxyPreserveHost On
|
|
ProxyAddHeaders On
|
|
<IfModule mod_headers.c>
|
|
RequestHeader set X-Forwarded-Proto "https"
|
|
RequestHeader set X-Real-IP %{REMOTE_ADDR}s
|
|
RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s
|
|
</IfModule>
|
|
</LocationMatch>
|
|
|
|
# ALTERNATIVE: Direkte ProxyPass-Konfiguration (funktioniert ab Apache 2.4.47)
|
|
# Falls die RewriteRule nicht funktioniert, kommentiere die obige LocationMatch aus
|
|
# und verwende stattdessen diese Konfiguration:
|
|
# ProxyPass /socket.io/ ws://localhost:3050/socket.io/
|
|
# ProxyPassReverse /socket.io/ ws://localhost:3050/socket.io/
|
|
# ProxyPass /socket.io/ http://localhost:3050/socket.io/
|
|
# ProxyPassReverse /socket.io/ http://localhost:3050/socket.io/
|
|
|
|
# Timeout für alle Proxy-Verbindungen (außerhalb von LocationMatch)
|
|
ProxyTimeout 3600
|
|
|
|
# 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>
|
|
|