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

you’re welcome!

Just came here to bump this thread. Went from HA Docker + SWAG Docker install to Hass OS so had to repoint DNS internally etc. It was this http: config in configration.yaml that was the issue.

Went from 1 hr of troubleshooting to 15 minutes. Thanks all!

This helped me too :+1:

Thank you!!!

Not sure why 127.0.0.1 would not be allowed by default but here we are. Thank you for posting the solution.

1 Like

[spanish] (aunque lo hablo muy mal, lo siento)
te agradezco muchissimo!

Me ayudo tambien eso (fuente : Accessing HASS.io through Apache, error "Unable to Connect to Home Assistant, Retry" - #5 by aktivalux)

In case anyone else is having this issue, the following fixed it for me.

sudo a2enmod proxy_wstunnel
sudo systemctl restart apache2

Mil gracias!

Hello,
So far this solution worked for me.
I reconfigured my docker.
So I recreated the docker of my HA, and I reused the same file space to keep my HA.

With HA local ip it works.
On the other hand, for public access, I use a Duckdns domain name which points to my reverse Nginx proxy in a docker. My Nginx’s docker has a bridge network while my HA’s has a host.

I have good in my configuration.yaml
http: use_x_forwarded_for: true trusted_proxies: - 172.18.0.2

Dans les logs de HA, j’ai 2023-01-10 10:06:05.518 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 172.18.0.2

I’m using the same configuration of my Nginx as before.
If you have different solutions.

Great, you have solved my problems. Thank you very much.

I have an issue, where I only want to add 2 subnets to my configuration:

http:
use_x_forwarded_for: true
trusted_proxies:
- x.x.x.x/15
- x.x.x.x/15

But when I reload configuration I get:
Invalid config for [http]: not a valid value @ data[‘http’][‘trusted_proxies’][0]. Got ‘x.x.x.x/15’. (See /config/configuration.yaml, line 17).

From documentation it accepts subnets, or am I wrong somewhere?

With a fresh install it does not seem feasible to change the configuration when having only access to the system console for a HAOS installation behind a proxy. I temporaralily had to bypass the proxy to be able to change the configuration.

And further more, the system is not happy with the fact I have two proxies…:

2023-02-24 01:16:51.294 ERROR (MainThread) [homeassistant.components.http.forwarded] Too many headers for X-Forwarded-For: ['10.33.2.69', '192.168.0.254']

EDIT:
To fix this with HAPROXY (on opnsense), I disabled the “X-Forwarded-For header” option in the “Public service”:
image
But I then added the option explicitly in the Option passtrough by adding it only when the header is absent (optioni forwardfor if-none):

And I got rid fo the BAD REQUEST 400 message.

You are my lifesaver! Websocket option in Nginx Proxy Manger solved my issues for HASS, Node-RED and code-server! Thank you very much!

2 Likes

Hi there. Followed your guide and it works fine in my Windows device but I can’t get acces via my Android phone or tablet.

Error code: not available ERR_ADDRESS_UNREACHABLE

Any suggestions? Thanks.

EDIT: A few minutes later it works.

1 Like

Perfection - this finally fixed hours of frustration :slight_smile:

1 Like

Thank you!!!

1 Like

@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!