Homeassistant behind caddy

I have pihole running on the device 192.168.0.101:1080/admin with apache2
and I have caddy running as well I have setup

I have also setup the ha.example.org to point to 192.168.0.101 in the pihole

ha.example.org {
    reverse_proxy http://192.168.0.101:8123
    tls {
        dns cloudflare _***************************u-VP
    }
}

http:
  # ip_ban_enabled: True
  login_attempts_threshold: 5
  base_url: https://ha.example.org
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.0.101 #IP_ADDR_OF_PROXY_SERVER

upon doing this I get 400: Bad Request error when visiting the domain

what am i doing wrong here ?

I don’t know caddy, but this problem is normally that only http request are proxied, and not the websockets. So probably adding websockets should fix it.

Not sure about cloudfare part, but here is mine. Been working well for years.

(logs) {
  log {
    output file /var/log/caddy/caddy.log {
      roll_size 5MiB
      roll_keep 5
      roll_keep_for 168h
    }
    format console
  }
}
(https_header) {
  header {
    Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"
    X-XSS-Protection "1; mode=block"
    X-Content-Type-Options "nosniff"
    Referrer-Policy "same-origin"
    -Server
    Content-Security-Policy "frame-ancestors xxx.org ha.xxx.org"
    Permissions-Policy "geolocation=(self) , microphone=()"
  }
}


https://ha.xxx.org {
  import https_header
  tls /etc/letsencrypt/live/ha.xxx.org/fullchain.pem /etc/letsencrypt/live/ha.xxx.org/privkey.pem {
    alpn http/1.1
  }
  reverse_proxy 192.168.10.7:8123
  import logs
  encode zstd gzip
}

Its being served on 443 externally, so you might need :port number at the start of the open brackets.