1. The problem I’m having:
I’m trying to retrieve prometheus metrics from the /metrics endpoint on a non-default port. I was able to expose the endpoint on port 2018 and bind it to the private IP interface.
Since Caddy, for several reasons that I’ll omit for simplicity, is behind an HAProxy instance, I enabled the PROXY protocol so that Caddy can parse X-Forwarded-For and correctly read the client IP.
The problem is that with the current configuration, when I visit http://192.168.1.0:2018/metrics, I get a “400 Bad Request” error.
Note: I do not go through the Load Balancer to retrieve the metrics but I contact directly the Caddy host.
2. Error messages and/or full log output:
The error message is a “400 Bad Request”. Right now the Caddy is handling hundreds of requests per seconds so the logs are unreadable.
3. Caddy version:
v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=
4. How I installed and ran Caddy:
a. System environment:
Ubuntu 20.04.6 LTS, Kernel Linux 5.4.0, go 1.23.4
b. Command:
/path/to/caddy run --environ --config /path/to/Caddyfile
d. My complete Caddy config:
{
default_bind 192.168.1.0
auto_https off
order ... some modules (ratelimit, waf, etc.)
log {
level INFO
output file /var/log/caddy/caddy-full.log {
roll_size 10mb
roll_keep 100
roll_keep_for 720h
}
format filter {
wrap json
fields {
request>remote_ip hash
request>headers>x-forwarded-for hash
request>headers>cf-connecting-ip hash
}
}
}
servers {
listener_wrappers {
proxy_protocol {
timeout 10s
# allow <cidrs>
}
tls
}
protocols h1 h2
metrics
}
}
:2018 {
metrics
}
:443 {
...
}
:80 {
...
}