Reverse proxy not working properly

Hello there,

I am having problems setting up a reverse proxy on my home assistant installation. The weird part is that I have access to the login page and also seem to get authorized (because a refresh-token is genereated) when I log in but then I get the message:

Unable to connect to Home Assistant.

When I hit the refresh button then it just brings me back to the login screen. I am thinking that it might have something to do with ProxyPassReverse setting in the apache2 configuration of the proxy server but actually do not know what I am doing wrong.

My setup is as follows:

I have a domain with a CNAME DNS-record pointing at the DuckDNS address which points at my homes IP. The external port 80 and 443 are forwarded to the same internal ports of the server running the reverse proxy.
The reverse proxy server is running apache2 with the following config and the same for port 80:

<VirtualHost *:443>
  ServerName home.example.org
  ProxyPreserveHost On
  ProxyRequests off
  ProxyPass /api/websocket ws://localhost:8123/api/websocket
  ProxyPassReverse /api/websocket ws://localhost:8123/api/websocket
  ProxyPass / http://localhost:8123/
  ProxyPassReverse / http://localhost:8123/

  RewriteEngine on
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule /(.*)  ws://localhost:8123/$1 [P,L]
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule /(.*)  http://localhost:8123/$1 [P,L]
</VirtualHost>

A created a SLL certificate for the external domain using certbot.

My home assistant config is the following:

http:
  base_url: external.domain.com
  use_x_forwarded_for: true
  trusted_proxies:
    - proxy_server_ip_address

I hope someone can help me. Thanks in advance!

I cant offer any guidance on apache, but I can point you to this guide I wrote a while back which still works.

you can also take a look at this, which is even easier
https://hub.docker.com/r/jlesage/nginx-proxy-manager/

1 Like

Hi
I had exactly the same problem, this tutorial seems to have fixed it.

Hope this helps

I feel really bad for not following the tutorial page completely. This is why I read over the command sudo a2enmod proxy_wstunnel which was the essential part I was missing. Now it works perfectly fine.
Thanks to both @juan11perez and @egglestn for helping me out on this one!

1 Like