Cannot access admin endpoint: "host not allowed: localhost:2019"

1. The problem I’m having:

I’m trying to access the /metrics endpoint, but the connection is refused.



curl -v http://localhost:2019/metrics

Host localhost:2019 was resolved.

IPv6: ::1

IPv4: 127.0.0.1

Trying [::1]:2019…

connect to ::1 port 2019 from ::1 port 52196 failed: Connection refused

Trying 127.0.0.1:2019…

Established connection to localhost (127.0.0.1 port 2019) from 127.0.0.1 port 60996

using HTTP/1.x

GET /metrics HTTP/1.1
Host: localhost:2019
User-Agent: curl/8.18.0
Accept: /

Request completely sent off
< HTTP/1.1 403 Forbidden
< Content-Type: application/json
< Date: Sun, 22 Mar 2026 11:03:08 GMT
< Content-Length: 45
<
{“error”:“host not allowed: localhost:2019”}

Connection #0 to host localhost:2019 left intact

2. Error messages and/or full log output:

mrt 22 12:04:15 nixos caddy[8004]: {“level”:“error”,“ts”:1774177455.8594854,“logger”:“admin.api”,“msg”:“request error”,“error”:“host not allowed: localhost:2019”,“status_code”:403}

3. Caddy version:

4. How I installed and ran Caddy:

  services.caddy = {
    enable = true;
    logFormat = ''
      format json
    '';
    globalConfig = ''
      metrics {
        per_host
      }

      admin {
      }
    '';
    virtualHosts."navidrome.louwers.dev".extraConfig = ''
      	        reverse_proxy http://127.0.0.1:${builtins.toString config.services.navidrome.settings.Port}
            	'';
    virtualHosts."grafana.louwers.dev".extraConfig = ''
      	        reverse_proxy http://127.0.0.1:${builtins.toString config.services.grafana.settings.server.http_port}
            	'';
};

a. System environment:

NixOS

d. My complete Caddy config:

{
        metrics {
                per_host
        }

        admin {
        }

        email REDACTED

        log {
                format json
        }
}

grafana.louwers.dev {
        log {
                output file /var/log/caddy/access-grafana.louwers.dev.log
        }

        reverse_proxy http://127.0.0.1:3000
}

OK this works

curl -v http://localhost:2019/metrics -H "Host: localhost"

Actually, pretty sure this is a bug. Thoughts?

localhost:2019 should be accepted as a Host.

Reported Admin endpoints rejecting `localhost:2019` as Host · Issue #7587 · caddyserver/caddy · GitHub

1 Like

Pretty sure it’s fixed by this PR

It’s released in 2.11.2. You didn’t share the version you’re using.

1 Like

I’m not really sure because I didn’t have the Caddy CLI installed.

I installed the Caddy CLI now, and it is 2.11.2.

I’m not sure what “didn’t have the Caddy CLI installed” means, because Caddy is a command. You’re using Nix, which is deterministic when it comes to versioning. It’s likely using the caddy reload command to reload config. Double check the deployed version.

1 Like

Sorry, what I meant was that it wasn’t on my PATH.

But I was able to confirm it’s actually 2.11.2

           │ ├─caddy.service
           │ │ └─68610 /nix/store/gi6wihyx04a4ljqhbdxxqzfkqmlsjfal-caddy-2.11.2/bin/caddy run --config /etc/caddy/caddy_config --adapter caddyfile

OK there is an issue in the documentation.

Setting origins localhost:2019 works.

Thanks for your help @Mohammed90