Mastering Secure Remote Access: Home Assistant with Nginx Proxy Manager
- #Home_Assistant
- #Nginx_Proxy_Manager
- #Remote_Access
- #Security
- #Networking
- #Docker
- #SSL

Mastering Secure Remote Access: Home Assistant with Nginx Proxy Manager
As your Home Assistant setup grows, the need for secure, reliable remote access becomes paramount. While Home Assistant Cloud (Nabu Casa) offers a convenient out-of-the-box solution, many users prefer a self-hosted alternative for greater control, privacy, and the satisfaction of building their own secure gateway. This is where Nginx Proxy Manager (NPM) shines. NPM simplifies the complexities of Nginx, making it easy to set up reverse proxies with free SSL certificates from Let's Encrypt, securing your Home Assistant instance and other services behind a single, user-friendly interface.
Why Nginx Proxy Manager for Home Assistant?
- Enhanced Security: Replaces direct port forwarding with a secure reverse proxy, handling SSL termination and protecting your Home Assistant instance from direct internet exposure.
- Free SSL/TLS Certificates: Automates the acquisition and renewal of Let's Encrypt certificates, ensuring all your external traffic is encrypted.
- Centralized Management: Manage multiple services (Home Assistant, AdGuard Home, Node-RED, etc.) from a single web interface, all under one public IP.
- Custom Domains: Use your own custom domain (e.g.,
home.yourdomain.com
) for a professional and memorable access point. - Websocket Support: Essential for Home Assistant's real-time communication, ensuring the mobile app and UI function flawlessly remotely.
Prerequisites
- Running Home Assistant Instance: Ensure your Home Assistant is fully set up and accessible on your local network.
- Domain Name: You'll need a domain name. This can be a purchased domain (e.g., via Namecheap, Cloudflare) or a free dynamic DNS service like DuckDNS, No-IP, or a subdomain of a purchased domain.
- Public IP Address: Your home network needs a public IP. If it's dynamic, ensure your domain name service updates your DNS records accordingly.
- Router Port Forwarding: Forward external ports
80
(HTTP) and443
(HTTPS) from your router to the internal IP address of the server where Nginx Proxy Manager will run. - Docker and Docker Compose: NPM is best run as a Docker container. Ensure Docker and Docker Compose are installed on your server (e.g., a Raspberry Pi, mini PC, or NAS).
Setting Up Nginx Proxy Manager
We recommend installing NPM via Docker Compose for easy management.
Step 1: Create Docker Compose File
On your server, create a directory for NPM (e.g., ~/docker/npm
) and inside it, create a docker-compose.yml
file:
version: '3.8'
services:
npm:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- '80:80'
- '443:443'
- '81:81'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
Explanation:
image: 'jc21/nginx-proxy-manager:latest'
: Specifies the official NPM Docker image.ports
: Maps external ports 80, 443 (for web traffic) and 81 (for NPM's admin UI) to the container's internal ports.volumes
: Persists configuration data and Let's Encrypt certificates, so they aren't lost if the container is recreated.
Step 2: Start Nginx Proxy Manager
Navigate to the directory containing your docker-compose.yml
and run:
docker compose up -d
This will download the image and start the NPM container in detached mode.
Step 3: Initial NPM Setup
Open your web browser and go to http://<your_server_ip>:81
(replace <your_server_ip>
with the IP of the machine running NPM).
The default credentials are:
- Email:
[email protected]
- Password:
changeme
You will be prompted to change these immediately. Do so and remember your new credentials.
Step 4: Create a Proxy Host for Home Assistant
In the NPM admin interface:
- Go to Hosts > Proxy Hosts and click Add Proxy Host.
-
Details Tab:
- Domain Names: Enter your desired subdomain for Home Assistant (e.g.,
ha.yourdomain.com
). - Scheme:
http
(NPM handles SSL, Home Assistant runs on HTTP internally). - Forward Hostname / IP: Enter the local IP address of your Home Assistant instance (e.g.,
192.168.1.100
). - Forward Port:
8123
(Home Assistant's default port). - Block Common Exploits: Enable for basic security.
- Websockets Support: Crucial! Enable this for real-time communication with Home Assistant.
- Domain Names: Enter your desired subdomain for Home Assistant (e.g.,
-
SSL Tab:
- SSL Certificate: Select
Request a new SSL Certificate
. - Force SSL: Enable (redirects HTTP to HTTPS).
- Email: Enter a valid email for Let's Encrypt notifications.
- I Agree to the Let's Encrypt Terms of Service: Check this box.
- HTTP/2 Support: Enable for better performance.
- SSL Certificate: Select
- Click Save. NPM will attempt to obtain an SSL certificate. This requires ports 80 and 443 to be correctly forwarded to the NPM server, and your domain's DNS records to point to your public IP.
Home Assistant Configuration
Once your proxy host is active in NPM, you need to tell Home Assistant about its new public face and to trust NPM as a proxy. Add the following to your Home Assistant's configuration.yaml
file:
homeassistant:
external_url: 'https://ha.yourdomain.com'
internal_url: 'http://192.168.1.100:8123' # Or your local DNS/IP
http:
use_x_forwarded_for: true
trusted_proxies:
- 172.16.0.0/12 # Example: Docker's default network range
- 192.168.1.50 # Example: Specific IP of your NPM server if not in Docker
# Add more trusted IPs/ranges if your NPM setup is complex
Important Notes:
external_url
: Set this to the public URL you configured in NPM.internal_url
: Set this to the local URL (IP and port) you use to access Home Assistant directly on your network. This helps the mobile app and other integrations determine if they are on your local network or accessing externally.http > use_x_forwarded_for: true
: Tells Home Assistant to use theX-Forwarded-For
header provided by the proxy to identify the client's actual IP address.http > trusted_proxies
: This is critical! Home Assistant will block requests from proxies it doesn't trust. You need to add the IP address or CIDR range of your NPM Docker container or host. If NPM is running in Docker on the same machine as Home Assistant, you might need to find Docker's internal network range (often172.16.0.0/12
or172.17.0.0/16
, depending on your setup). If NPM is on a separate host, use that host's local IP.
After modifying configuration.yaml
, restart Home Assistant.
Device Integration Tips & Remote Access
With NPM in place, accessing your Home Assistant remotely becomes seamless:
- Home Assistant Mobile App: When setting up the app, use your new
https://ha.yourdomain.com
URL. The app is smart enough to switch tointernal_url
when it detects you're on your home network. - Voice Assistants: If you're not using Nabu Casa for Google Assistant/Alexa integration, you'd typically need to expose your Home Assistant via a custom skill/action that connects to your public URL.
- Webhooks/Callbacks: For integrations that require external callbacks (e.g., some cloud services or custom webhooks), provide your NPM-proxied URL.
Best Practices for a Reliable Ecosystem
- Keep NPM Updated: Regularly pull the latest Docker image for NPM to benefit from security fixes and new features (
docker compose pull && docker compose up -d
). - Secure NPM Admin: Always change the default admin credentials immediately. Use a strong, unique password.
- Enable HSTS: In the SSL tab of your proxy host, consider enabling HSTS (HTTP Strict Transport Security) for an additional layer of security. This tells browsers to always connect via HTTPS, even if HTTP is requested.
- Firewall Rules: On your NPM server, ensure only ports 80, 443, and 81 (if you need remote admin access) are open. Configure your router's firewall to allow incoming connections only on 80/443 to the NPM server.
- Dynamic DNS Client: If you have a dynamic public IP, ensure your DDNS client (e.g., built into your router, or a separate Docker container) is reliably updating your domain's A record.
- Backup NPM Configuration: Regularly back up the
data
andletsencrypt
volumes of your NPM Docker container. This ensures you can quickly restore your proxy configurations and certificates if needed. - Rate Limiting & Access Lists (Advanced): For increased security, NPM offers advanced settings like custom Nginx configurations. You can implement IP-based access lists or basic rate limiting to protect against brute-force attacks if needed.
Troubleshooting Common Issues
- SSL Certificate Errors:
- Ensure ports 80 and 443 are correctly forwarded from your router to your NPM server.
- Verify your domain's DNS A record points to your *public* IP address.
- Check NPM logs (
docker compose logs npm
) for Let's Encrypt errors.
- Home Assistant Not Loading / Websocket Issues:
- Double-check that "Websockets Support" is enabled in your NPM proxy host.
- Ensure
trusted_proxies
in Home Assistant'sconfiguration.yaml
correctly includes the IP address or Docker network range of your NPM instance.
- '403: Forbidden' or 'Not Found':
- Verify your "Forward Hostname / IP" and "Forward Port" in NPM are correct for Home Assistant.
- Check Home Assistant logs for errors related to connections.
- Browser Redirect Loops: Ensure
Force SSL
is enabled in NPM and that yourexternal_url
in Home Assistant ishttps://
.
Conclusion
Integrating Nginx Proxy Manager with Home Assistant provides a robust, secure, and highly customizable solution for remote access. By following these steps, you gain full control over your smart home's external connectivity, securing it with valid SSL certificates and centralizing the management of multiple web services. This not only enhances your system's security but also empowers you with the knowledge to maintain a resilient and reliable smart home ecosystem, truly making your smart home your own.

NGC 224
Author bio: