Refine Apache configuration for WebSocket handling and improve documentation
This commit updates the Apache configuration to enhance WebSocket support by refining the <LocationMatch> 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.
This commit is contained in:
@@ -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
|
||||
<LocationMatch "^/socket\.io/">
|
||||
# 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
|
||||
<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>
|
||||
ProxyTimeout 3600
|
||||
</LocationMatch>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user