0

My virtual host setup:

<VirtualHost *:443>
 
 
    ProxyPreserveHost On
        ProxyRequests off
        ProxyPass /home-assistant/api/websocket ws://192.168.1.125:8123/api/websocket
        ProxyPassReverse /home-assistant/api/websocket ws://192.168.1.125:8123/api/websocket
        ProxyPass /home-assistant http://192.168.1.125:8123
        ProxyPassReverse /home-assistant http://192.168.1.125:8123
 
        RewriteEngine on
        RewriteCond %{HTTP:Upgrade} =websocket [NC]
        RewriteRule /home-assistant/(.*)  ws://192.168.1.125:8123/$1 [P,L]
        RewriteCond %{HTTP:Upgrade} !=websocket [NC]
        RewriteRule /home-assistant/(.*)  http://192.168.1.125:8123/$1 [P,L]
 
 
    SSLEngine On
 
 
        DocumentRoot /home/michal/sites/webmail
 
 
    ServerAlias www.mydomain.com
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
</VirtualHost>

But it does not work. When accessing https://example.com/home-assistant home assistant logo is loaded and I can see home assistant sitl tries to load its resources from example.com/ url, not example.com/home-assistant/ url, so it won't load.

How to make it working? I guess it will work if proxy is at top level '/', but not at '/home-assistant'

How to fix my rewrite rules to get all redirections made to example.com/home-assistant instead of example.com/?

4
  • I'm not sure if my use case is included there. I'm looking for solution for this specific case, your link is more general Commented Apr 20 at 21:34
  • 3
    The problem is typically that on its own mod_proxy doesn’t change the content it retrieves from the back-end server. It doesn’t change a reference to for example /css/style.css to /home-assistent/css/style.css - a long time ago I wrote a longer explanation here serverfault.com/a/561897/37681 for Apache 2.2 that is still mostly relevant and there is a second answer there as well for the current Apache 2.4 version
    – HBruijn
    Commented Apr 21 at 3:22
  • Excellent answer, because it seems that's the same case - reverse proxy at path, not top level url. It however seems to be more complicated than I expected. Commented Apr 21 at 9:05

1 Answer 1

3

Configure home assistant with the correct URL.

Go to Configuration > General Input your external and internal url in the appropriate boxes. Press save

https://community.home-assistant.io/t/base-url-deprecation-but-unclear-what-to-do-about-it/200377

It's always preferable to fix these issues by configuring the backend properly instead of having the reverse proxy rewrite the HTML on the fly.

3
  • I'm not sure if I really want to mess with backend configuration. Won't it break access from LAN via internal ip? Commented Apr 21 at 9:07
  • It most probably will. Just use the external address. Commented Apr 22 at 15:34
  • Not an solution in this case. I need to keep local access working Commented Apr 22 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .