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

Which part? It solves an issue where HA is being a proxy . So make sure that is your setup.

The fix has 3 steps

  1. Check configuration->basic->log for reverse proxy error. Note the IP address in the error message. if you don’t have it, then you have a different problem.
  2. Edit the configuration.yaml file
http:
  use_x_forwarded_for: true
  trusted_proxies:
    - XXX.XXX.XXX.XXX # Add the IP address of the proxy server

  1. Restart your Home Assistant server.

The problem should be resolved.

I’ve had problems with HA behind cloudflare’s proxy , and I had to turn it off for external access to the server to work. I reconfigured my proxy setup over the weekend, and HA was the last server I had to get working behind cloudflare’s proxy.

I’m done! I can enjoy the last few hours of my weekend now, lol. This thread saved those last few hours so thanks!

4 Likes

Thanks @kiwijunglist for this post. I had a different issue, but pointed me into the right direction to solve it.
I am running HASS Supervised on a pi behind a traefik reverseproxy in a docker on a synology NAS. This NAS has two ethernet ports.
I configured only one of them in HASS which worked for months. But suddenly I got the 400.
Adding the 2nd IP Address in the http section solved it.

1 Like

Thanks. It worked. It took some time to figure out what IP should I provide in my case. And 127.0.0.1 worked for me.

1 Like

This solved my issue of using reverse proxy to HA.

2 Likes

Hi!
Thank you very much, man. It works.
The problem was breaking my head.
Grateful.

1 Like

Just created an account to say “Thank you”. Was chasing my tail for the last 2 days with this.

1 Like

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