Using Traefik with Grafana causes infinite 302 redirects to `/login`

I am new to Grafana and have been trying to implement it into my stack. I use Traefik to act as a reverse proxy and load balancer. I was able to setup a rule in Traefik that will point requests visiting my server with the path being exactly /grafana or beginning with /grafana/. This is similar to what is written for configuring Grafana with HAProxy with a sub path.

When I visit my server at https://example.com/grafana I am redirected to https://example.com/grafana/login with a 302. This happens 20 times until Chrome terminates the connection for redirecting too many times. I believe that Grafana is functioning properly but may be incorrectly configured of the reverse proxy and/or Traefik is passing the request to Grafana in a way that confuses Grafana.

I set my Grafana server root URL to /grafana and Traefik has the Grafana service using the following configuration:

labels:
  - 'traefik.enable=true'
  - 'traefik.http.routers.grafana.rule=Path(`/grafana`) || PathPrefix(`/grafana/`)'
  - 'traefik.http.routers.grafana.entrypoints=web'
  - 'traefik.http.middlewares.grafana-compress.compress=true'
  - 'traefik.http.services.grafana.loadbalancer.server.port=3000'

What value for the root_url do you have in your grafana.ini? https://grafana.com/docs/grafana/latest/installation/behind_proxy/#examples-with-sub-path-ex-http-foo-bar-grafana

I have set the GF_SERVER_ROOT_URL environment variable to https://mydomain.com/grafana and the GF_SERVER_DOMAIN environment variable to mydomain.com.

Okay, super! Let me see if I can reproduce this one. Will get back to you.

1 Like

I just realized that you might not do a url rewrite. Please try to add this env to your grafana instance:

GF_SERVER_SERVE_FROM_SUB_PATH=true

as specified here: https://grafana.com/docs/grafana/latest/installation/configuration/#serve-from-sub-path

1 Like