I want to leave un update here in case someone will need it in the future.
I finally managed to accomplish my goal!
I’m now able to access locally HomeAssistant Docker container using an encrypted connection (https) and without the need to buy a domain name.
That’s my current setup:
I have a Raspberry Pi 5 running Pi-Hole and Home Assistant in Docker containers.
In another docker container i run Nginx Proxy Manager (NPM) (https://nginxproxymanager.com/).
I created a local DNS record in Pi-Hole that points to my raspberry-pi IP adress (that i set as static in my router). As local domain I choosed homeassistant.name.home.arpa ( home.arpa is the recommended TLD for home networking, as indicated in IETF RFC 8375).
In home assistant compose file I removed the port 8123 and added an external docker network (that enables communications with NPM).
In the NPM interface i added a proxy host that redirects homeassistant.name.home.arpa to the docker containter homeassistant, port 8123 ( That NPM recognize since they are in the same network).
I edited HomeAssistant’s configuration.yaml to add:
http:
use_x_forwarded_for: true
trusted_proxies:
- 192.168.0.0/25
using the IP adress range of my Local Network.
In this way I am able to access Home Assistant interface via a domain name instead of IP:8123.
To add SSL certificates I used mkcert, a super simple tool that creates a local Certification Authority and use it to sign a SSL certificate for homeassistant.name.home.arpa
Then in NPM interface i uploaded this certificate and used it for HomeAssistant proxy.
In this way I am able to access Home Assistant interface via https:// homeassistant.name.home.arpa
I then imported the Certificate Authority in my other devices trust store, in this way the browsers trust the SSL certificates and don’t complain about it being self-signed.
When I type this domain https:// homeassistant.name.home.arpa in the browser ( or via HomeAssistant companion app) Pi-Hole redirects to Raspberry Pi. On raspberry pi there’s the NPM container that is listening on port 443, it recognize the domain name and redirects to Home Assistant docker container. This provides me with the Home Assistant interface without the warnings that the connection is not secure. And all stays contained to my local network.
Thanks for developing such a useful and empowering tool! Keep it up!
Bye
Here there’re the docker compose files I use, in case they are useful to someone:
Home Assistant compose.yaml
services:
homeassistant:
container_name: homeassistant
hostname: homeassistant
image: 'ghcr.io/home-assistant/home-assistant:stable'
volumes:
- /PATH_TO_YOUR_CONFIG:/config
- /etc/localtime:/etc/localtime:ro
- /run/dbus:/run/dbus:ro
networks:
- proxied
restart: unless-stopped
environment:
TZ: Europe/Amsterdam
networks:
proxied:
name: proxied
external: true
Nginx Proxy Manager compose.yaml
services:
nginx-proxy-manager:
image: 'jc21/nginx-proxy-manager:latest'
container_name: nginx-proxy-manager
restart: unless-stopped
ports:
- '80:80' # HTTP
- '81:81' # Pannello di controllo NPM
- '443:443' # HTTPS
volumes:
- ./npm-data:/data
- ./npm-letsencrypt:/etc/letsencrypt
networks:
- proxied
networks:
proxied:
name: proxied
driver: bridge
ipam:
config:
- subnet: 172.21.0.0/16
gateway: 172.21.0.1