From 90b5f8d63d0eba03a11f542d998eeff59b789bcb Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sat, 15 Nov 2025 23:19:27 +0100 Subject: [PATCH] Refine Apache configuration for WebSocket handling and improve documentation This commit updates the Apache configuration to enhance WebSocket support by refining the directive. It clarifies the need for multiple LocationMatch blocks and ensures proper handling of WebSocket upgrades and fallbacks to HTTP. Additionally, it encapsulates header settings within a conditional block for better compatibility. These changes improve the server's ability to manage real-time communication effectively. --- apache.conf.example | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/apache.conf.example b/apache.conf.example index 5a0d286..fa30930 100644 --- a/apache.conf.example +++ b/apache.conf.example @@ -31,26 +31,24 @@ ProxyRequests Off # WebSocket-Proxy für Socket.IO - # WICHTIG: Diese LocationMatch muss VOR den anderen ProxyPass-Direktiven stehen + # WICHTIG: Diese LocationMatch-Blöcke müssen VOR den anderen ProxyPass-Direktiven stehen + # WICHTIG: mod_proxy_wstunnel muss aktiviert sein (sudo a2enmod proxy_wstunnel) + + # WebSocket-Upgrade erkennen und weiterleiten (wss:// -> ws://) + # Verwende RewriteRule mit mod_rewrite für WebSocket-Upgrades - # WebSocket-Upgrade erkennen und weiterleiten 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 ^/?(.*) ws://localhost:3050/$1 [P,L] + RewriteCond %{HTTP:Upgrade} !=websocket [NC] + RewriteRule ^/?(.*) http://localhost:3050/$1 [P,L] - # Fallback für HTTP (Polling) - muss nach dem RewriteRule stehen - ProxyPass http://localhost:3050/socket.io/ - ProxyPassReverse http://localhost:3050/socket.io/ - - # Headers für WebSocket ProxyPreserveHost On - ProxyAddHeaders On - RequestHeader set X-Forwarded-Proto "https" - RequestHeader set X-Real-IP %{REMOTE_ADDR}s - RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s - - # Timeouts für WebSocket-Verbindungen + + RequestHeader set X-Forwarded-Proto "https" + RequestHeader set X-Real-IP %{REMOTE_ADDR}s + RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s + ProxyTimeout 3600