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

Hi

With the latest update of home assistant v2021.7.0 I started getting “400 Bad Request” error when I tried to access HA via my external http/https address. I could still access home assistant without error via the local IP address.

If you check out the breaking changes if you are running a proxy you need to add

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - XXX.XXX.XXX.XXX # Add the IP address of the proxy server

Reference - HTTP - Home Assistant

However it still didn’t work for me. I tried using the IP address of my local server and also my WAN address but I was still getting the error! It’s because you need to use the internal docker IP address for your proxy container…

The solution is to check the home assistant log file for the internal docker IP proxy address to use.

Here is the relevant entry in the home assistant log file:
"A request from a reverse proxy was received from 172.18.0.4, but your HTTP integration is not set-up for reverse proxies"

You can generate this error in your log file by removing the http proxy setup from your configuraiton.yaml and then restart home assistant and try to access home assistant and generate the bad request error, then you can search the log file for the correct IP address to use.

… Or you can also find the correct IP address using portainer under
Networks → Compose_Default. Then scroll down and find the Lets_Encrypt docker container docker IP address.

… Or you can use the command line
List all docker networks:
docker network ls
Inspect a specific network to find the IP address of a container:
docker network inspect <network_name>

Hope that helps someone!

137 Likes

That helped me, thanks!

2 Likes

Мужык ты крут, Спасибо большое! Чуть мозг не сломал, пока не нашел ваш ответ)
Dude your are awesome, that helped me!

1 Like

Thank you, it helps me

1 Like

Thank you very much for this magnificent post.
It also worked for me.

1 Like

Thank you very much for your detailed instructions - your advice worked great for me.

1 Like

Thank you very much.

My configuration
HomeAssistant as a VM 192.168.1.43:8123
Ubuntu VM running Nginx docker 192.168.1.42 (force SSL)
Nginx has home.mydomain.net pointing towards 192.168.1.43

Nginx is configured to allow me to access https://home.mydomain.net internally. Recently I have been getting these 400 bad requests when trying internally or externally from WAN.

As mention in the first post by Kiwijunglist, there is a document from Home Assistant providing instructions on what to do.

The following is all I needed to do, and a reboot of course.

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.1.42

5 Likes

That’s good.

Thank you! Worked perfectly!!!

1 Like

Thanks, saved the day for me too

1 Like

How do you get this information from the log? I’m not seeing anything. I’ve set the level to debug but it never spits out an IP address or a message similar to yours. Do I need to add anything new to NGINX?

Thanks, it worked!

1 Like

Maybe you have a different problem, might need to post in a new forum post with the symptoms and specifics.

Thank you! This was it! I thought I was losing my mind.

2 Likes

Massive thank you.

1 Like

Turned out my docker was on 2 different network segments. Once I updated the IP to the correct docker network started working. Thanks.

1 Like

Well done…I love you!

1 Like

Maybe not that relevant, but I had to whitelist my gateway for my home assistant docker network, it had nothing to do with my proxy (which to be fair is a separate docker network, so I’m adding complexity). Without the log file, I would never have tried that.

Just an FYI in case it helps anyone.

http:
use_x_forwarded_for: true
trusted_proxies:
- XXX.XXX.XXX.XXX # Add the IP address of the gateway of the docker HA network.

1 Like

This helped me a great deal, many thanks

1 Like

thanx! lifesaver!

1 Like