I have Discourse reverse proxied behind Caddy, and it turns out that the solution was to add
header_up X-Real-IP {remote_host}
to the reverse_proxy section in my Caddyfile, which I hadn’t needed before.
I figured out that X-Real-IP was needed due to the similar error message in this post.
I hope this helps someone having a similar problem.