Apache reverse proxy

Given that I’ve seen quite a few of these and spent quite a while trying to get HA to work through a reverse proxy, I thought I’d share my working config.

In my case, I have an Apache reverse proxy on a remote server which connects back over VPN to the local HA machine, but that makes no difference in this instance, it only changes the IP address in use!

I have the below (and, importantly, the order matters and I have no rewrites necessary to make this work!):

ProxyPreserveHost On
ProxyRequests off

ProxyPass /api/websocket ws://<IP of HA box>:8123/api/websocket upgrade=websocket
ProxyPassReverse /api/websocket ws://<IP of HA box>:8123/api/websocket

ProxyPass / http://<IP of HA box>:8123/
ProxyPassReverse / http://<IP of HA box>:8123/

This not only works once, but through a DOUBLE reverse-proxy.

I have an external dedicated server, running LetsEncrypt to get free SSL.
That reverse proxies it with the above config over a VPN to a device that runs my network (it does this via HTTP, by the way, because it’s going over the VPN anyway).

That device then has the same config with Apache, and reverse proxies it again to the actual HA box that lives on the same network (I’m using HA OS on an RPi).

And… it now just works.

Given that I’ve spent inordinate amounts of time to realise how simple it was, I thought I’d post it for others.

The critical part is the upgrade=websocket for the appropriate websocket URL, which if your Apache doesn’t support it, you need to upgrade.

Strangely, it didn’t work when I had that on the bottom ProxyPass statement, though it’s supposed to be clever enough to do that.

1 Like

This is awesome! I was having issues getting this to work on my Sophos Home Firewall.

The one thing it doesn’t seem to know is where the admin account is logging in from. I know my admin account doesn’t allow external access but its logging in.

Did you have any luck on that.

ProxyPreserveHost On
ProxyRequests on


ProxyPass /api/websocket ws://127.0.0.1:8123/api/websocket disablereuse=on
ProxyPassReverse /api/wecbsocket ws://127.0.0.1:8123/api/websocket
ProxyPass / http://127.0.0.1:8123/ disablereuse=on
ProxyPassReverse / http://127.0.0.1:8123/


RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:8123/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://127.0.0.1:8123/$1 [P,L]

configuration.yaml:

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 127.0.0.0/24