Basic auth with Caddy webserver

Here's a simple Caddyfile to add basic auth in front of prometheus and alertmanager :

myserver.mydomain.tld:9090 {
  gzip
  tls off
  log stdout
  basicauth / admin P@ssword
  proxy / prometheus:9090  
}
myserver.mydomain.tld:9093 {
  gzip
  tls off
  log stdout
  basicauth / admin P@ssword
  proxy / alertmanager:9093
}

Caddy is a lightweigth webserver written in Go https://caddyserver.com/.

You can use it with a docker-compose.yml like this :

version: "2"
services:
  prometheus:
    image: "prom/prometheus"
    (...)

  alertmanager:
    image: "prom/alertmanager"
    (...)

  caddy:
    image: "abiosoft/caddy"
    ports: 
      - "9093:9093"
      - "9090:9090"
    volumes:
      - "$PWD:/etc/"

No extra configuration needed on prometheus side.

Rate this tip

If you think this tip by commarlacommarla is useful — rate it up!

rating: +1+x
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License