Enable websockets behind apache2 proxy

Does anyone have the config for websockets running behind Apache2? Right now, websockets return a 400 Bad Request.

grafana version? We need to add Apache to our reverse proxy install instructions. Have you searched this forum?

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]

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

But the websocket path is known to be /api/live/ws, isn’t it? The mod_proxy_wstunnel module is deprecated and superseded by mod_proxy_http:

I have Grafana listening on a UNIX socket and base path (as other web applications are running on the same machine). Config looks like that:

ProxyPass /grafana/api/live/ws unix:/run/grafana/grafana.sock| upgrade=websocket
ProxyPass /grafana unix:/run/grafana/grafana.sock|
ProxyPassReverse /grafana unix:/run/grafana/grafana.sock|

But for some reason it doesn’t work yet. I’m sitting behind Cloudflare and in browser console I still see the 524, indicating that the server is not listening on the wss://my.domain.org/grafana/api/live/ws requests. Need to test on a local test server, not sure whats missing.

Grafana does answer to websocket requests OOTB, right? I just became aware of this because of browser console errors, and when searching for websockets in Grafana, the first I found is a related data source plugin, which i don’t need because it’s about daily acquired data, where live updates are nonsense.