Loki: Serving from external URL + subpath

I want to reach my Loki instance from a subpath like so:

<mydomain>/monitoring/loki/<loki specific path>

I can’t find any information on how to configure that? Is it even possible? I know that it is with Prometheus using flags like --web.external-url but I don’t know how similar Loki is to Prometheus.

Okay I have checked the options with docker run grafana/loki -help and the flag I mentioned is not included there. So I guess it is not possible? Grepped for url and the only remotely related option I found is -frontend.downstream-url with the description: “URL of downstream Prometheus”.

Sorry to resurrect this old question, but I have exactly the same.

I have a few services (including Loki) behind a caddy V2 web server and I would like to use a subpath to only have one public FQDN.

Could not find any hints on this.

Is it possible ?

Or are there other best practices to run Loki behind a reverse proxy on a subpath ?
Any hint would be greatly apreciated.

Many thanks.

I had some help from the community and could solve this.

TL;DR you can define the prefix on a loki 2.3+ server with:

server:
  http_listen_port: 3100
  http_path_prefix: /myprefix

And with more details, in case it helps someone else:

This assume all the services are defined in a single docker-compose setup with vanilla names, the Caddy server is the single entry point for the outside world.

Caddy v2 reverse proxy conf:

:8080 {
    route /myprefix* {
        reverse_proxy loki:3100
    }
  
    reverse_proxy myapp:8081 
}

Yaml conf for Loki:

...
server:
  http_listen_port: 3100
  http_path_prefix: /myprefix
...

Yaml Conf for promtail:

...
clients:
  - url: http://loki:3100/myprefix/loki/api/v1/push
...

You can then define the datasource in Grafana with: https://my.example.com/myprefix.

And it works!

I have the same problem and for me, it does not work.


example.com {

  handle /promtail* {

    reverse_proxy 127.0.0.1:9080

  }

  handle /grafana* {

    reverse_proxy 127.0.0.1:3000

  }

  handle /loki* {

    reverse_proxy 127.0.0.1:3100

  }

  handle /prometheus* {

    reverse_proxy 127.0.0.1:9090

  }
}

Loki config:


server:

  http_listen_port: 3100

  grpc_listen_port: 9095

  http_path_prefix: /loki

Promtail config:


server:

  http_listen_port: 9080

  http_path_prefix: /promtail

Same problem here:
Setting http_path_prefix: /loki

$ curl http://localhost:3100/loki/loki/api/v1/status/buildinfo {"version":"HEAD-e0af1cc","revision":"e0af1cc8a","branch":"HEAD","buildUser":"root@5004faa13e2e","buildDate":"2022-12-09T19:23:40Z","goVersion":""}
but e.g.
$ curl http://localhost:3100/loki/loki/api/v1/labels 404 page not found
Reverse proxy isn’t even used at this stage. Version 2.5.0 did find the labels, but not the values of the labels.