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

I have tried everything with this but still cannot get it to work.

I have a reverse proxy via IIS URL rewrite. The logs show the local gateway IP but always with a different port number after it. I’ve added my entire network (/24) to trusted_proxies and still same thing.

Thanks it worked for me. :+1:

1 Like

And yet a thank you!

Running traefik on docker… the log entry tip helped me

2 Likes

hola
donde hay q escribir eso?
gracias

1 Like

Hey,

You will need to add what i quoted earlier in your configuration file. The link below will tell you where to find your configuration file.
Configuration.yaml - Home Assistant (home-assistant.io)

[Spanish]
Tienes que modificar tu documento manualmente, se llama: configuration.yaml

> 
> http:
>   use_x_forwarded_for: true
>   trusted_proxies:
>     - 192.168.1.42
1 Like

Ughh thank you so much. My Alexa integration had been broken by this and took me this long to figure out why.

1 Like

Thank you!

1 Like

This did the trick, thanks.

Is there a good way of configuring it so that it’s not sensitive to IP changes i.e. if the IP address of reverse proxy container changes in future?

2 Likes

It seems to be static but you could just add the whole subnet if you wanted.

Thank you! You saved me a bunch of heart ache when I moved HA to docker.

1 Like

I think mine has dynamic ip:

Logger: homeassistant.components.http.forwarded
Source: components/http/forwarded.py:112
Integration: HTTP (documentation, issues)
First occurred: 9:51:20 PM (10 occurrences)
Last logged: 9:51:26 PM

  • Received X-Forwarded-For header from an untrusted proxy 172.69.35.236
  • Received X-Forwarded-For header from an untrusted proxy 172.69.34.165
  • Received X-Forwarded-For header from an untrusted proxy 108.162.215.21

Any idea how to deal with this?

@crpgbogor Try

trusted_proxies:
- 108.162.215.21
- 172.69.35.0/24
1 Like

Thanks. I tried but still doesn’t work.
This is the error log:

  • Received X-Forwarded-For header from an untrusted proxy 172.70.142.93
  • Received X-Forwarded-For header from an untrusted proxy 172.70.142.223

Would it be possible if we just input the docker gateway? Anyone know how to obtain docker’s gateway using ssh?

Update: I input 0.0.0.0/24 but still doesn’t work

Update:
This appears to be an issue with cloudflare proxy. When the proxy is turned off (DNS only), the page is resolving as normal.

I should probably enter cloudflare’s IP range into trusted proxy, but I have no idea the IP range they use.

Update: Finally solved.

I put all of cloudflare’s ip range in trusted proxy and it is now working as before. Thank you all for your help.

See Cloudflare’s IP range here.

This has been incredibly helpful, but I still have an issue happening.

  • I’m running on Synology DSM 7, with support for wildcard certs.
  • My DDNS subdomain for Home Assistant is ha.<mydomain>.synology.me.
  • I have set up the reverse proxy on my Synology
  • I have set up the HTTP x_forward/trusted proxy statements in HA, (clearing the 400 error).

I was so incredibly happy to see a Home Assistant login screen after doing this! But when I entered my credentials, and yes, I know they are correct, it seems I get logged in, but then something gets hung up, and I get the screen below.

The resulting URL that gets me the picture below is:

https://ha.<mydomain>.synology.me/lovelace

So it’s as if I’m logging in correctly, but then something is getting hung on the dashboards.

Any help??

2 Likes

Forgot to mention in the post above… I check home-assistant.log and there’s nothing at all… pretty frustrating.

Try https://ha..synology.me , same problem? Also press CTRL+SHIFT+F5.

kiwijunglist… yep, nothing works, even if actually typing the “https://” before my “ha” URL. Interesting issue… it’s making it to the HA instance and through the authentication (it looks like)… but the HA instance doesn’t like it after that.

Did you enable websockets on the nginx configuration?

4 Likes