Refine Apache configuration for WebSocket handling and improve fallback mechanisms
This commit updates the Apache configuration to enhance WebSocket support by clarifying the <LocationMatch> 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.
This commit is contained in:
@@ -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)
|
||||
<LocationMatch "^/socket\.io/">
|
||||
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
|
||||
<IfModule mod_headers.c>
|
||||
RequestHeader set X-Forwarded-Proto "https"
|
||||
RequestHeader set X-Real-IP %{REMOTE_ADDR}s
|
||||
|
||||
Reference in New Issue
Block a user