Unable to connect to homeassistant over HTTPS with external Nginx Proxy Manager

Hello everyone,
I’ve recently configured my homeassistant setup to be reachable over https using a subdomain with Nginx Proxy Manager on an extra machine.
This setup seems to have worked for a bit until I updated homeassistant core to 2024.7.2. I’m not entirely sure whether this issue was caused by the update or not as it sporadically disappears.

When I access homeassistant using my subdomain https://homeassistant.mydomain.com I often get the message Unable to connect. Retrying from Homeassistant. When I then open a new tab and connect over HTTP using the homeassistant.local:8123 domain everything loads as it should. Going back to the tab where I connected using the subdomain, everything suddenly works upon a page refresh.

My Homeassistant is installed as Homeassistant OS in a VM on a Proxmox server. My reverse-proxy is running in an LXC on the same server.

This is the relevant excerpt of my homeassistant configuration.yaml file:

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.1.107 # Proxy in LXC on atlas server
    - 192.168.1.103 # HA IP
    - 192.168.1.0/24 # LAN IP range

And this is my NPM configuration:

I would also add a picture of the SSL page but since I am a new user I apparently can only post 1 embedded image. On the SSL page I have configured my certificate with a wildcard for subdomains (`*.mydomain.com) and enabled everything except HSTS subdomains because I don’t quite understand what that does.

I also configured my subdomain in the homeassistant network settings for both Internet and LAN access (even though my server is only reachable from my network).

Finally, I don’t see any error messages in my logs regarding prohibited access.

Does someone have an idea what could cause this issue?

As outside access “sometimes” work, my first intuition would be a network issue between your reverse proxy and HA, or maybe a DNS issue.

Difficult to say more…

The thing that makes this issue really weird in my opinion is that the subdomain with https does work but only after I first connect over the http domain. After some time it stops working again though

So I think I found the problem?

According to the nginx logs, the reverse proxy was unable to resolve the forward hostname, even though it kind of worked because I would get the connection failed screen from homeassistant.

Anyway, I changed the forward hostname to the IP address of my homeassistant installation and now it seems to be working. If I don’t get the same error within 2 days I will mark this as the solution