From 7b209c3fbd4e048e8a171e33a5c755b5c18111ea Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski <55490546+ALameLlama@users.noreply.github.com> Date: Sat, 27 Apr 2024 13:26:16 +1000 Subject: [PATCH] Fix Apache Proxy Websockets (#1967) * fix: websockets for apache proxy * fix: web socket protocol --- scripts/site-types/apache-proxy.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/site-types/apache-proxy.sh b/scripts/site-types/apache-proxy.sh index c4016c53e..0e04d793b 100644 --- a/scripts/site-types/apache-proxy.sh +++ b/scripts/site-types/apache-proxy.sh @@ -23,16 +23,35 @@ if [ -n "$2" ] then if ! [[ "$2" =~ ^[0-9]+$ ]] then + if ! [[ "$2" =~ ^https: ]] + then + socket=$(echo "$2" | sed -E "s/^http(s?):\/\//ws:\/\//g") + else + socket=$(echo "$2" | sed -E "s/^http(s?):\/\//wss:\/\//g") + fi + proxyPass=" + RewriteEngine On + RewriteCond %{HTTP:Upgrade} =websocket [NC] + RewriteRule /(.*) $socket/ [P,L] + ProxyPass / ${2}/ ProxyPassReverse / ${2}/ " else proxyPass=" + RewriteEngine On + RewriteCond %{HTTP:Upgrade} =websocket [NC] + RewriteRule /(.*) ws://127.0.0.1:$2/ [P,L] + ProxyPass / http://127.0.0.1:$2/ ProxyPassReverse / http://127.0.0.1:$2/ " fi else proxyPass=" +RewriteEngine On +RewriteCond %{HTTP:Upgrade} =websocket [NC] +RewriteRule /(.*) ws://127.0.0.1/ [P,L] + ProxyPass / http://127.0.0.1/ ProxyPassReverse / http://127.0.0.1/ "