Caddy reverse proxy issue

Sonarr version (exact version): 2.0.0.5344
Mono version (if Sonarr is not running on Windows): Windows
OS: Windows 10 Ent
Debug logs: Debug and trace:
https://drive.google.com/file/d/13qzZRsZ7NWhC3TlP5BufI5NYIgfy_neE/view?usp=sharing, https://drive.google.com/file/d/15ejHzSkKC9MW8iK0r4mdwQ_YVYFMpiaJ/view?usp=sharing

Description of issue:
Having a weird issue with Sonarr behind a caddy reverse proxy where caddy passes through to Sonarr but Sonarr throws a 400 back (HTTP Error 400. The request hostname is invalid.)
Sonarr works fine on the host through localhost:8989, and that’s what I’m forwarding to in caddy.
Initially I thought it was a caddy issue but have eliminated that with the team on the caddy forum.

I’ve added debug and trace logs here in the hope it might enlighten someone - I couldn’t find anything relevant but not really sure what I’m looking for.

Hopefully someone can help, it’s been driving me nuts.

EDIT: Sonarr config file if helpful

<Config>
  <LogLevel>Info</LogLevel>
  <Port>8989</Port>
  <UrlBase>/sonarr</UrlBase>
  <BindAddress>*</BindAddress>
  <SslPort>9898</SslPort>
  <EnableSsl>False</EnableSsl>
  <ApiKey> </ApiKey>
  <AuthenticationMethod>None</AuthenticationMethod>
  <LaunchBrowser>False</LaunchBrowser>
  <UpdateMechanism>BuiltIn</UpdateMechanism>
  <Branch>master</Branch>
  <SslCertHash></SslCertHash>
</Config>

Have you tried running Sonarr once as an admin? That’ll register all hostnames on the 8989 port, it’ll also open the firewall port (so disable that if you want). I suspect that caddy is passing the request URL to Sonarr and because that URL is rejected by http.sys it’s failing.

Thanks Marcus. I’ve got it working for now. Seems like a combination of things. The run as admin definitely helped, but also seems Sonarr throws back everything as /sonarr/. Declaring /sonarr* in caddy helped.

If you set a URL base of /sonarr then yes, if you just want subdomain.domain.com to work then you can remove the URL base.