Franck Nijhof c464056402
Making our website faster, cleaner and prettier (#9853)
* 🔥 Removes octopress.js

* 🔥 Removes use of root_url var

* 🔥 Removes Octopress generator reference from feed

* 🔥 Removes delicious support

* 🔥 Removes support for Pinboard

* 🔥 Removes support for Disqus

* 🔥 Removes support for Google Plus

* ↩️ Migrate custom after_footer to default template

* ↩️ Migrate custom footer to default template

* ↩️ Migrate custom header to default template

* 🔥 Removes unused template files

* 🚀 Places time to read directly in post template

* 🚀 Removes unneeded capture from archive_post.html template

* 🔥 🚀 Removes unused, but heaving sorting call in component page

* 🚀 Merged javascripts into a single file

* 🔥 Removes more uses of root_url

* 🚀 Removal of unneeded captures from head

* 🔥 🚀 Removal of expensive liquid HTML compressor

* 🔥 Removes unneeded templates

* 🚀 Replaces kramdown with GitHub's CommonMark 🚀

* 💄 Adds Prism code syntax highlighting

*  Adds support for redirect in Netlify

* ↩️ 🔥 Let Netlify handle all developer doc redirects

* ✏️ Fixes typo in redirects file: Netify -> Netlify

* 🔥 Removes unused .themes folder

* 🔥 Removes unused aside.html template

* 🔥 Removes Disqus config leftover

* 🔥 Removes rouge highlighter config

* 🔥 Removes Octopress 🎉

* 💄 Adjust code block font size and adds soft wraps

* 💄 Adds styling for inline code blocks

* 💄 Improve styling of note/warning/info boxes + div support

* 🔨 Rewrites all note/warning/info boxes
2019-07-15 22:17:54 +02:00

3.8 KiB

title, description, redirect_from
title description redirect_from
Apache Proxy Configure Apache to work with Home Assistant as a subdomain /cookbook/apache_configuration/

This example demonstrates how you can configure Apache to act as a proxy for Home Assistant.

This is useful if you want to have:

  • a subdomain redirecting to your Home Assistant instance
  • several subdomain for several instance
  • HTTPS redirection

Subdomain

So you already have a working Apache server available at example.org. Your Home Assistant is correctly working on this web server and available at http://localhost:8123

Enable mod_proxy_wstunnel by running if you encounter issues while serving Home Assistant through your proxy:

$ sudo a2enmod proxy_wstunnel

To be able to access to your Home Assistant instance by using https://home.example.org, add the following file to /etc/httpd/conf/extra/ as hass.conf

<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>

and make sure that this file is read by Apache's main configuration file /etc/httpd/conf/httpd.conf

...
Include conf/extra/hass.conf
...

If you don't want HTTPS, you can change <VirtualHost *:443> to <VirtualHost *:80> or better consider redirecting all HTTP to HTTPS.

In case you are getting occasional HTTP 504 error messages ("Gateway Timeout") or HTTP 502 messages ("Bad Gateway") when accessing the Web UI through your proxy, try adding disablereuse=on to both ProxyPass directives:
<VirtualHost *:443>
  [...]
  ProxyPass /api/websocket ws://localhost:8123/api/websocket disablereuse=on
  [...]
  ProxyPass / http://localhost:8123/ disablereuse=on
  [...]
</VirtualHost>

Multiple Instance

You already have Home Assistant running on http://localhost:8123 and available at home.example.org as describe before. The configuration file for this Home Assistant is available in /home/alice/.homeassistant/configuration.yaml

You want another instance available at https://countryside.example.org

You can either :

  • Create a new user, bob, to hold the configuration file in /home/bob/.homeassistant/configuration.yaml and run Home Assistant as this new user
  • Create another configuration directory in /home/alice/.homeassistan2/configuration.yaml and run Home Assistant using hass --config /home/alice/.homeassistant2/

In both solution, change port number used by modifying configuration.yaml

http:
  server_port: 8124
  ...

Start Home Assistant: Now, you have another instance running on http://localhost:8124

To access this instance by using https://countryside.example.org add to /etc/httpd/conf/extra/hass.conf

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

HTTP to HTTPS redirection

Add to your /etc/httpd/conf/extra/hass.conf

<VirtualHost *:80>
  ServerName example.org
  ServerSignature Off

  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
</VirtualHost>