Configuring Grafana with suburls in Rancher


I want to start Grafana under suburl (say /grafana).

docker run -d -p 3000:3000 --name=grafana -e “GF_SERVER_ROOT_URL=http://server-ip/grafana” -e “GF_SECURITY_ADMIN_PASSWORD=secret” grafana/grafana

For accessing the grafana under suburl, i want to add the above container to rancher haproxy load balancer.

What would be the custom configuration command to enable reverse proxy so that accessing the load balancer would redirect to grafana url properly.


You don’t need custom config for that, just define a service for grafana with those settings and then add a balancer with a rule mapping /grafana to the service.

Thanks for the reply. I tried that but doesn’t work i.e. after adding the LB service to grafana and accessing the LB URL doesn’t bring up Grafana page.

I think for Grafana , reverse proxy need to be configured. I would like to know the haproxy configuration command to enable reverse proxy.

This is a little more than transparent reverse proxying, as Grafana still expects the requests to reach it with the root url of /. To achieve that, HAProxy needs to rewrite the URL used in the request and strip off the /grafana component before sending it on. I’m afraid I don’t have time to help formulate the configuration for that but this should give you a good idea of how to do so:

That’s odd… why does it have a GF_SERVER_ROOT_URL if it doesn’t use that to change the expected root URL?

If my understanding is correct, it’ll add the root URL to any links in response content, but not actually accept requests on it. The proxy needs to strip them. Not the best approach IMHO.

Perhaps a cheap shot questioning the requirements but could you use a unique sub-domain or domain name instead? I have HAProxy setup to serve Grafana, Kibana, Elastic, Prometheus and more routing on the sub-domain, so something like this;

Thanks for the reply. We want to run it as as suburl. Running Grafana behind haproxy would solve the issue but I was trying to use the rancher load balancer service for this purpose instead of creating another separate container for haproxy. But need information on configuring the same. I tried using the options in the above link but no luck getting it to work.

The Rancher LB is HAProxy. Can you post what you tried please?

For now, as a workaround we are using nginx. Will update this post with more details regarding HAProxy.