Edit: Oh wait, it works in incognito mode… Why would Chrome redirect me? I Thought I used the HTTPS Everywhere Chrome extension but it seems to be disabled…
We don’t actually set the X-Real-IP header or X-Forwarded-Port header automatically, because these are seldom used. I would be surprised if this particular application requires all of those headers though. It’d be worth simplifying as much as possible because for some reason people keep adding redundant config lines in and I can’t understand where they come from or why.
(Side note that does not apply in this situation: technically the Host header going upstream is set to {http.request.hostport} by default, not {http.request.host} – the difference being the port, but that usually only applies when sites are served on non-standard ports. In this case, the sites are on the standard :443 port, so clients don’t include the port in their Host header to Caddy. If your site was on a non-standard port, like :1234, then the incoming Host header might be example.com:1234 and if you wanted only example.com going to the backend, then that line as written would be the right way to strip the port. But again, that’s not necessary here.)
We should probably output lint warnings when we see these kinds of config lines that are likely irrelevant/redundant.
@matt@francislavoie I found something somewhere saying you needed transparent in Caddy v1 to proxy to Home Assistant and then I found another thing saying these directives were Caddy v2’s equivalent of transparent. Before I added them the hosted home assistant site couldn’t make a WebSocket connection back to the server; the upgrade always failed.
Maybe your backend requires one of those headers? But websockets “just work” without any changes. Please try removing them, then add them one-by-one until it works. I guarantee if all of them are needed, then it’s a bad backend; it might just need one of them, but it’s still not conventional in that case.
Based on the nginx config described here: Reverse proxy using NGINX - Community Guides - Home Assistant Community, I suppose a vanilla reverse_proxy would work, unless it’s sensitive to the Host header. First try a plain reverse_proxy, then if it doesn’t connect, add header_up Host {host} – the linked guide shows that it might require the original request’s host name without the port. I dunno why. Anyway that’s what that line does. But start simple, then try different things until it works.