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 export Apple Health / Google Fit training activity to TCX format

  I own a Xiaomi Smart Band 7, and recently, my Mi Fitness app stopped syncing running activities to Strava. Mi Fitness supports syncing dat...