How to configure Apache2 to proxy WebSocket connection (BrowserSync for example), if it\'s made on the same URL, with only difference being header \"Upgrade: websocket\" and
Thanks a lot to metalim! I publish the full configuration here for reference:
<VirtualHost *>
ServerName example.org
ServerAlias *.example.org
ServerAdmin sysadmin@example.org
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) ws://192.168.1.1/$1 [P,L]
ProxyPass / http://192.168.1.1/ retry=1
ProxyPassReverse / http://192.168.1.1/
ErrorLog /var/log/apache2/example.org.error.log
CustomLog /var/log/apache2/example.org.access.log combined
</VirtualHost>
Answering myself.
Using RewriteEngine, hint given by this post, and WebSocket handshake specification:
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:3000/$1 [P,L]
ProxyRequests off
<Location />
ProxyPass http://127.0.0.1:3000/
ProxyPassReverse /
</Location>