Cloudflared with docker - getting 404 for HA [Solved somehow]

I’m not real capable but have been following various tutorials and not having luck. I have HomeAssistant running in docker (not the OS or Supervised) and trying to get remote access. Got the cloudflare connector working with my NAS, which I configured on cloudflare the same time as the HASS. The NAS works with the connector, but the HASS gives me a 404 not found.

I’ve tried other remote options like NGINX and Caddy but got lost and never figured them out. (I have an opnsense router). From reading it seemed the cloudflare option may be a bit more secure, especially for someone that has a hard time understanding how to keep things real secure… but don’t really know. I had tailscale working for remote access a year ago or so, but something changed with them and I can’t get it working now though haven’t tried too hard.

I don’t need remote access very often at all… really rarely at this point . but can see the value in the future as I get some security stuff working for when traveling. Hence the cost of nabu casa seems a bit much at this point considering I was rarely using remote.

So my thinking is possibly the problem that my HA is running on network “host” and the cloudflared is on “bridge”. Found a few what I thought workarounds, but no luck yet. Also possible that I made a typo at cloudflare when doing the connector, but I don’t really think so and I can’t figure out how, on their website, to check… their system confounds me.

My configuration.yaml with all the IPs I tried:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
homeassistant:
    name: Home
    latitude: 64.499350
    longitude: -165.414680
    elevation: 4
    customize: !include customize.yaml
    external_url: "http://192.168.40.70:8123"
    internal_url: "http://192.168.40.70:8123"
# Following added from this tutorial: https://nuxx.net/blog/2024/01/08/nginx-on-opnsense-for-home-assistant/
http:
  use_x_forwarded_for: true
  ip_ban_enabled: true
  trusted_proxies:
     - 192.168.40.70/32
     - 192.168.1.1/32
     - 172.21.0.0/16  #added for cloudflared https://www.wassupy.com/2024/12/self-hosting-home-assistant-with-cloudflare-tunnels.html
     - 172.30.33.0/24  #added for cloudflared..trying to find something that works
  cors_allowed_origins:  #added for cloudflared 
    - http://192.168.40.70
    - https://hass.mydomain.com

So for trusted proxies, I had the 192.168.1.1/32 before trying to configure cloudflared… so just left it alone. It is the lan gateway. I may have tried it with that commented out. Then I added the 172.21… address I got from the cloudflared logs. The 172.30… I figure was a hail mary from help files here, but I think that is when HA is running as an OS or supervised with cloudflared as an add-on. But don’t know and it didn’t seem to make a difference. The NAS access that works is on a different vlan… 192.168.30.0 say.

Nothing different in the docker-compose.yaml from the tutorials.

The 172.21.0.0/16 comes from a tutorial that pulls that from the command:
docker network inspect bridge which is the network cloudflared is on. It is the subnet. From cloudflared in Portainer I see the IP as 172.21.0.4… so that should be good.

Cloudflared Logs show the nas.mydomain.com but no mention of hass.mydomain.com.

Anything jumping out at anyone? I assume it is possible with HA and Cloudflared being on different networks. Thanks!

Hey, nevermind the above. I think I solved it somehow. I did a bunch of stuff… went back into cloudflare DNS and deleted the CNAME of hass and then redid the published application route, which added the CNAME back. That did nothing to help as far as I know. I played around with IP addresses in the configuration.yaml to no avail. Then I entered network_mode: host in docker-compose.yaml. And suddenly it works.

I had entered that long before and couldn’t get things working. I would look at the container in Portainer and see that cloudflared was still in bridge network, so figured that entry (network_mode) didn’t work. But maybe it does.

So still not sure if that was it or other tweaks that just took effect, but there I go.

thanks for looking.