Bad Gateway behind Reverse Proxy

I haven’t taken a deep look but perhaps this slightly older thread may offer some help: LetsEncrypt certificates fail in domain validation - #20 by mafftor