Tuesday, May 18, 2021

[How To] Apache Websockets WSS in a Subfolder

 The following syntax can be used to run websocket connections in Apache in a subfolder : 

# /websocket1 to port 2085

RewriteCond %{REQUEST_URI} /websocket1 [NC]

RewriteCond %{HTTP:Upgrade} "(?i)websocket" [NC,OR]

RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]

RewriteRule ^/(.*)$ ws://127.0.0.1:2085/$1 [P,QSA,L]


# /websocket2 to port 3126

RewriteCond %{REQUEST_URI} /websocket2 [NC]

RewriteCond %{HTTP:Upgrade} "(?i)websocket" [NC,OR]

RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]

RewriteRule ^/(.*)$ ws://127.0.0.1:3126/$1 [P,QSA,L]

The above need to be used in a SSL virtualhost.

For a non-SSL virtualhost, one can simply use:

ProxyPass "/websocket1" "ws://127.0.0.1:2085/"
ProxyPass "/websocket2" "ws://127.0.0.1:3126/"

No comments:

Post a Comment

How to disable Debian 12 sleep on production servers

 Debian 12 has power saver enabled by default which causes your server to go to sleep if there is no mouse / keyboard interaction. To resolv...