Configure Prometheus on a Sub-Path behind Reverse Proxy
While configuring my new Prometheus and Grafana setup, I had to spend some time figuring out how to get the Prometheus UI to correctly serve on a sub-path, e.g. example.com/prometheus
.
I won’t bore you with all the intermediate steps I tried (and failed!), but rather jump straight to the conclusion: You need to set the --web.external-url
flag to /prometheus/
:
|
|
From the Prometheus manpage:
|
|
(By the way: I’m not sure what’s so hard about just documenting the command line flags on the offcial documentation pages instead of an unhelpful “just run prometheus -h”)
Then configure the reverse proxy so that it forwards requests for /prometheus/
to the address Prometheus is listening on, but without stripping the prefix (!).
Traefik v2:
|
|
Traefik v1:
|
|
Nginx:
|
|
Thanks also to this issue for some inspiration.
Hope this helps, happy monitoring!