Reverse Proxy for Home Assistant with macOS Server 5.3.1
Created a website within Server App for EXTERNALHOSTNAME.TLD
Selected SSL Certificate for EXTERNALHOSTNAME.TLD
Enabled web app in Advanced Settings
This webapp/reverseproxy setup works and Home Assistant is working as expected with no functional issues via macOS Server, BUT, the catch is that any request matching “/api/websocket” is reverse proxied through to home assistant, for any other hostnames, which isn’t ideal.
I cant figure out how to configure this upstream Service Proxy to apply this reverse proxy for /api/websocket only for the external hostname for home assistant and not reverse proxy it for all other hostnames.
Any pointers on how to get the websocket reverse proxy set up correctly just for the relevant hostname?
The three files configured for this to work are as follows;
Webapp PLIST file /Library/Server/Web/Config/apache2/webapps/EXTERNALHOSTNAME.ha_webapp.plist;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- See man pages for webapp.plist(5) and webappctl(8) for information about this example webapp.plist -->
<plist version="1.0">
<dict>
<key>includeFiles</key>
<array> <!-- Include files are activated in virtual host when webapp is started -->
<string>/Library/Server/Web/Config/apache2/httpd_ha_webapp.conf</string>
</array>
<key>name</key>
<string>EXTERNALHOSTNAME.ha_webapp</string>
<key>displayName</key> <!-- Name shown in Server app -->
<string>ReverseProxy - HomeAssistant</string>
<key>installationIndicatorFilePath</key> <!-- The presence of this file indicates web app is installed -->
<string>/Library/Server/Web/Config/apache2/httpd_ha_webapp.conf</string>
<key>sslPolicy</key><!-- Determines webapp SSL behavior -->
<integer>0</integer> <!-- 0: default, UseSSLWhenEnabled -->
<!-- 1: UseSSLAlways -->
<!-- 2: UseSSLOnlyWhenCertificateIsTrustable -->
<!-- 3: UseSSLNever -->
<!-- 4: UseSSLAndNonSSL -->
</dict>
</plist>
Webapp CONF file /Library/Server/Web/Config/apache2/httpd_ha_webapp.conf;
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://INTERNALHOSTNAME:8123/
ProxyPassReverse / http://INTERNALHOSTNAME:8123/
MacOS Server Service Proxy CONF file /Library/Server/Web/Config/Proxy/apache_serviceproxy_customsites_ha.conf
ProxyPass /api/websocket ws://INTERNALHOSTNAME:8123/api/websocket
ProxyPassReverse /api/websocket ws://INTERNALHOSTNAME:8123/api/websocket