Homeassistantはアドオンを追加する毎に、
configuratorは3128
tasmoadminは9541
と、どんどんポートを勝手に使っていてしまいます。
これは困った・・・
ドメインで管理しようにも、これじゃあできないです。
サブディレクトリで対応しようかと思ってやってみたのですが、ログインリダイレクトでURLがルートに設定されていたりするアドオンがあるので無理そう。
具体的にはTasmoadminですが。
であれば、サブドメインで対応するしかないです。
サブドメインを複数作るには、その数だけ証明書が必要になりますが、実はワイルドカードという、サブドメイン全般に有効な証明書があるんです。
これがあると1つで全てのサブドメインに対応できるので、取得するしかありません。
ということで、ワイルドカードの無料証明書を取得していきます。
ワイルドカード証明書の取得
この辺りを参考にワイルドカード証明書を取ります。
1 | sudo ./certbot-auto --manual certonly -d *.ドメイン名 --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory -m メールアドレス --agree-tos |
DNSの変更
途中でDNSにTXTレコードを追加しろと言われるので以前設定したcloudflareのDNSに追加します。
ついでに追加したいサブドメインもCNAMEレコードで登録します。
こんな感じ。
なんかほとんどマスキングされてますが。。。
apache2 のconfigを変更
こんな感じで。
以前とは違い、デフォルトの証明書を今回取得したもの、以前取得したサブドメインなしの証明書をhass.ioメインに設定しています。
さらに、configのサブドメインで来た際に3218にプロキシするようにしています。
ちなみにtasmoadminやnode-redの設定もしてます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | <IfModule mod_ssl.c> <VirtualHost _default_:443> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /etc/letsencrypt/live/ドメイン-0001/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/ドメイン-0001/privkey.pem <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> </VirtualHost> <VirtualHost *:443> ServerAdmin root@localhost ServerName ドメイン SSLCertificateFile /etc/letsencrypt/live/ドメイン/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/ドメイン/privkey.pem ProxyPreserveHost On ProxyRequests off ProxyPass / http://localhost:8123/ ProxyPassReverse / http://localhost:8123/ ProxyPass /api/websocket ws://localhost:8123/api/websocket ProxyPassReverse /api/websocket ws://localhost:8123/api/websocket 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> <VirtualHost *:443> ServerAdmin root@localhost ServerName config.ドメイン ProxyPreserveHost On ProxyRequests off ProxyPass / http://localhost:3218/ ProxyPassReverse / http://localhost:3218/ RewriteEngine on RewriteRule /(.*) http://localhost:3218/$1 [P,L] </VirtualHost> <VirtualHost *:443> ServerAdmin root@localhost ServerName tasmo.ドメイン ProxyPreserveHost On ProxyRequests off ProxyPass / http://localhost:9541/ ProxyPassReverse / http://localhost:9541/ RewriteEngine on RewriteRule /(.*) http://localhost:9541/$1 [P,L] </VirtualHost> <VirtualHost *:443> ServerAdmin root@localhost ServerName nr.ドメイン ProxyPreserveHost On ProxyRequests off ProxyPass / http://localhost:1880/ ProxyPassReverse / http://localhost:1880/ RewriteEngine on RewriteRule /(.*) http://localhost:1880/$1 [P,L] </VirtualHost> <VirtualHost *:443> ServerAdmin root@localhost ServerName line.ドメイン ProxyPreserveHost On ProxyRequests off ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ RewriteEngine on RewriteRule /(.*) http://localhost:8080/$1 [P,L] </VirtualHost> </IfModule> |
確認
確認は当然ながらWANから行います。
DNSが伝播したら確認します。。。
https://configurator.ドメイン名
にアクセスします。
configuratorの設定
configuratorの設定をしましょう。
1 | sudo docker exec -it homeassistant /bin/bash |
で入って、
/config/configuration.yaml
に下記を追加します。
1 2 3 4 5 | panel_iframe: configurator: title: Configurator icon: mdi:wrench url: https://config.ドメイン/ |
そしたらdockerからログアウトして再起動します
1 | sudo docker restart homeassistant |
完了!!