From 5b4a5ba501de3dc8494d5a99f24f0e82882a8678 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sat, 15 Nov 2025 23:21:59 +0100 Subject: [PATCH] Refine Apache configuration for WebSocket handling and improve fallback mechanisms This commit updates the Apache configuration to enhance WebSocket support by clarifying the directive and ensuring proper handling of WebSocket upgrades. It introduces a fallback mechanism for HTTP polling and emphasizes the need for mod_rewrite and mod_proxy_wstunnel. These changes improve the server's capability to manage real-time communication effectively. --- apache.conf.example | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apache.conf.example b/apache.conf.example index fa30930..2867512 100644 --- a/apache.conf.example +++ b/apache.conf.example @@ -31,19 +31,25 @@ ProxyRequests Off # WebSocket-Proxy für Socket.IO - # WICHTIG: Diese LocationMatch-Blöcke müssen VOR den anderen ProxyPass-Direktiven stehen + # 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) # WebSocket-Upgrade erkennen und weiterleiten (wss:// -> ws://) - # Verwende RewriteRule mit mod_rewrite für WebSocket-Upgrades + # Die RewriteRule wird nur ausgeführt, wenn Upgrade-Header vorhanden ist + # Andernfalls wird ProxyPass verwendet (für HTTP-Polling) RewriteEngine on RewriteCond %{HTTP:Upgrade} =websocket [NC] + RewriteCond %{HTTP:Connection} =upgrade [NC] RewriteRule ^/?(.*) ws://localhost:3050/$1 [P,L] - RewriteCond %{HTTP:Upgrade} !=websocket [NC] - RewriteRule ^/?(.*) http://localhost:3050/$1 [P,L] + + # 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 RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Real-IP %{REMOTE_ADDR}s