Home assistant (400 Bad Request) Docker + Proxy - Solution

@francisp 3 years later, you’re still saving lives. Thanks!

2 Likes

Thank you, that was the solution for me too.

1 Like

Absolute hero!

Thank you for this.

My setup is interesting in that I have Home Assistant OS running as a virsh/QEMU container, and Swag running in docker on the same physical hardware. Swag has a sample reverse proxy configuration for homeassistant already that mostly worked, except for the 400 error I was encountering on the HA side.

Sure enough, the logs said that HTTP integration was not set-up for reverse proxies. Adding in the trusted proxy IP address in to the configuration and restarting Home Assistant did the trick.

This has allowed my local voice assistant to work :slight_smile:

I was running into this as well when setting HomeAssistant up using NGINX Proxy Manager. Based on what’s stated in this thread you have to enable websockets for it to work right. Go into the host settings and turn the websockets option on and you’re good to go.

thanks, it’s really helpful!

Thank You!!

Hello please i really need help.
I did everything thing and still have the same problem

Today something strange happened to me.

I use the Nginx Proxy Manager for my reverse proxy. I host it in HA as a HA addon. In my configuration.yaml I have added the lines in the op with an IP similar to 172.30.33.4.

But, this morning the connection didn’t work through the proxy domain.

I had to recheck the IP via the log and update it in configuration.yaml. Does this make sense? That the IP changes being hosted in the same machine?

In the meanwhile, I tried to use 127.0.0.1 as the IP and didn’t work.

Today again, at 1AM, the IP from the Nginx Proxy Manager HA addon has changed from 172.30.33.4 to 172.30.33.5. Seeing this pattern, i have changed the trusted_proxies entry to 172.30.33.0.

I had the same issue and thanks for hint! If you go to developer mode of your browser there was error on network related to WebSocket (wss protocol).
I set in Nginx:
Websockets Support

and it works!
Thanks a lot!!!

it works, but if I restart my docker, the IP is changing. Any suggestions?

@hsch0 this is the working configuration for today:

# Cloudflare setting to unlock reverse proxy
http:
   use_x_forwarded_for: true 
   trusted proxies:
	- 172.30.33.0/24
	- 103.21.244.0/22
	- 103.22.200.0/22
	- 103.31.4.0/22
	- 104.16.0.0/13
	- 104.24.0.0/14
	- 108.162.192.0/18
	- 131.0.72.0/22
	- 141.101.64.0/18
	- 162.158.0.0/15
	- 172.64.0.0/13
	- 173.245.48.0/20
	- 188.114.96.0/20
	- 190.93.240.0/20
	- 197.234.240.0/22
	- 198.41.128.0/17

Define a network for your reverse proxy so that you know what subnet you should set in HA’s config.

In your reverse proxy’s docker compose add a network with an IP range. It can be a range you choose, just make sure it’s within the local addresses for IPv4:

services:
  reverse-proxy:
    # Your existing proxy defined here.
    networks:
    - local-proxy-network

networks:
  local-proxy-network:
      ipam:  
        config: 
         - subnet: 172.19.0.0/24

In Home Assistant, set the same IP range as above.

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 172.19.0.0/24

You might have to stop your proxy instance, not just restart it to get this new network setting applied. You can of course add other docker containers to this network if you wish.

This should help you @hsch0 @jmdv

1 Like

Thanks for your tip with the websockets. 3 1/2 years later it still helps .

1 Like

Legend. This solved my issue. Thank you!

1 Like

Hi guys, I have a strage problem using duckdns/nginx.

So let me recap:

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - XXX.XXX.XXX.X/XX

The issue I have:

How is it possible that remotely I can assess to 8123 and not to 4445??

I can’t figure out what’s happening…If someone has more knowledge to share please you are welcome :slight_smile:

Shoud I turn on CloudShare in Nginx configuration menu? I don’t know what it is
I’m using MariaDB but I don’t set anything more in Nginx config

Gracias por tu ayuda me fue de mucha utilidad.

The solution didn’t work for me, until I ticked Websockets support in the nginx proxy manager and https/2 too, although I have no idea why. Until I did that it just said it couldn’t reach it - even though I got the branded page from the server. Now it works fine, thanks.

Just FYI - you can add the entire docker bridge range, just in case it ever changes, eg:
172.18.0.0/16