Skip to content

Home Assistant with reverse proxy

Fixing local network access

By default, Home Assistant really does not seem to like being accessed through a reverse proxy. Trying to do so results in this error message on the loaded web page:

400: Bad Request

Since my home server will be running several web services, I need to use a reverse proxy to allow access to all of them.

To fix this, if you don't already know it, first find the reverse proxy IP address in the Home Assistant log file config/home-assistant.log:

2022-12-31 11:02:48.837 ERROR (MainThread) [homeassistant.components.http.forwarded] A request from a reverse proxy was received from 172.18.0.3, but your HTTP integration is not set-up for reverse proxies

Then you can add the reverse proxy's IP address to Home Assistant's configuration file config/configuration.yaml. In this case that would be:

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 172.18.0.3

Fixing external Internet access

The above worked for the Docker reverse proxy I was using to allow access to multiple sites on the same host from the LAN. But it did not work to allow access from the Nginx on my VPS, to be able to access Home Assistant from outside my LAN.

To make that work, I needed to add this to my Nginx config:

server {
  server_name <something>;
  [... more config ...]

  location / {
      proxy_redirect off;
      proxy_set_header Host homeassistant.lan;
      proxy_pass http://homeassistant.lan:80;
      proxy_set_header    Upgrade     $http_upgrade;
      proxy_set_header    Connection  "upgrade";
  }
}

The name homeassistant.lan is configured in my /etc/hosts file to the OpenVPN IP address of the home server. Adding the last two lines in the location block is what made external Home Assistant access work for me.