Enable websockets behind apache2 proxy

I have a working setup. The main trick is described in the apache documentation at mod_proxy_wstunnel - Apache HTTP Server Version 2.4. There the configuration is described to setup proxying when you don’t know what the websocket URLs will be in advance.
The trick is to use mod_rewrite to rewrite websocket requests (identified by the appropriate headers) before passing them to mod_proxy: mod_proxy understands websockets since version 2.4.47 of apache.

A working apache snippet is as follows:

<VirtualHost *:80>
  ServerName grafana.example.com

  ProxyRequests off
  ProxyPreserveHost on

  ProxyPass / http://grafana.monitoring.svc.cluster.local:3000/ disablereuse=On
  ProxyPassReverse / http://grafana.monitoring.svc.cluster.local:3000/

  RewriteEngine on
  RewriteCond %{HTTP:Upgrade} websocket [NC]
  RewriteCond %{HTTP:Connection} upgrade [NC]
  RewriteRule ^/?(.*) "ws://grafana.monitoring.svc.cluster.local:3000/$1" [P,L]
</VirtualHost>

This setup is working with grafana live tailing the logs using loki.