Setting Up Nginx Reverse Proxy for Home Assistant OS on KVM

Abstract: Solve external access issues for Home Assistant OS on KVM by configuring Nginx reverse proxy with WebSocket and SSL support.

Created: 2026-08-23 by
Configure Nginx as a reverse proxy for Home Assistant OS on KVM by forwarding port 8123 traffic to the guest's internal IP. This setup allows secure external access while keeping the virtual machine isolated. The configuration requires specific Nginx directives to handle WebSocket connections and proper SSL termination, ensuring seamless integration with your home server infrastructure without exposing the underlying hypervisor directly to the internet.

Network Configuration and Prerequisites

Before configuring the web server, ensure that the Home Assistant OS instance is running correctly within your KVM environment. The guest operating system must have a static internal IP address assigned via DHCP reservation or manual configuration in the VM settings. This stability is crucial because any change in the internal IP will break the reverse proxy routing immediately. Verify connectivity by pinging the guest from the host machine using the command ping [guest-ip]. If the ping fails, check the network bridge configuration on the KVM host. You may need to adjust firewall rules to allow traffic between the host and the guest. For detailed troubleshooting on network isolation issues, refer to our guide on How to Fix UFW Blocking KVM Guest from Getting IP Address and Accessing Network. Ensure that port 8123 is open on the guest's firewall if applicable, although typically the guest handles its own local services.

Nginx Installation and Initial Setup

Install the latest version of Nginx on your host machine if it is not already present. On Debian-based systems, use apt install nginx. Once installed, verify the service status with systemctl status nginx. It is recommended to create a dedicated configuration file for Home Assistant rather than modifying the default site configuration. Create a new file at /etc/nginx/sites-available/home-assistant. This separation makes future updates and debugging significantly easier. Disable the default site to avoid conflicts by running ln -sf /dev/null /etc/nginx/sites-enabled/default. Then, enable your new configuration with ln -s /etc/nginx/sites-available/home-assistant /etc/nginx/sites-enabled/home-assistant. Always test the syntax before restarting the service to prevent downtime. Use nginx -t to validate your configuration files. If the test passes, restart Nginx with systemctl restart nginx.

Core Reverse Proxy Configuration

The core of the solution lies in the Nginx server block. You must define the server name, which should be your desired domain or subdomain for accessing Home Assistant. Configure the listen directive to accept traffic on port 443 for HTTPS. Inside the server block, add a location block for the root path. Use the proxy_pass directive to forward requests to the Home Assistant instance on port 8123. Crucially, you must include headers to pass the correct client information. Add proxy_set_header Host $host;, proxy_set_header X-Real-IP $remote_addr;, and proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;. These headers ensure that Home Assistant knows the original requester's details, which is vital for authentication and logging. Without these, you might encounter issues where the application thinks all requests are coming from localhost.

WebSocket Support and SSL Termination

Home Assistant relies heavily on WebSockets for real-time updates, such as state changes and automation triggers. Standard HTTP proxies often drop these connections unless explicitly configured. To fix this, add specific upgrade headers within your location block. Include proxy_http_version 1.1; and proxy_set_header Upgrade $http_upgrade;. Also, set proxy_set_header Connection "upgrade";. These lines tell Nginx to maintain the persistent connection required for WebSocket communication. If you plan to terminate SSL at the Nginx level, you must point to valid certificate files. Use ssl_certificate and ssl_certificate_key directives pointing to your Let's Encrypt or self-signed certificates. Self-signed certificates will trigger browser warnings, so obtaining a trusted certificate is highly recommended for a smooth user experience. For more insights on managing certificates in reverse proxy scenarios, see Configuring SSL Passthrough with Certificates on Nginx Reverse Proxy for Paperless-ngx.

Troubleshooting Common Issues

After applying the configuration, you may encounter connection errors. A common issue is the 502 Bad Gateway error, which usually indicates that Nginx cannot reach the backend service. Check if the Home Assistant container or VM is running and listening on the expected port. Another frequent problem involves redirect loops caused by incorrect internal URL configurations in Home Assistant. Ensure that the base_url in your Home Assistant configuration matches the public domain you are accessing. If you experience intermittent disconnections, review your WebSocket headers again. Sometimes, firewall rules on the host machine can interfere with established connections. If you suspect broader networking problems, such as the server becoming unreachable entirely, consult Troubleshooting Home Server: Suddenly Unreachable Over Internet. Regularly check Nginx logs located at /var/log/nginx/error.log for detailed error messages that can guide your fixes.

Frequently Asked Questions

Why do I get a 502 Bad Gateway error?

This error typically means Nginx cannot connect to the upstream Home Assistant service. Verify that the guest VM is running and that the internal IP address matches the one in your Nginx configuration. Check if port 8123 is accessible from the host machine using curl http://[guest-ip]:8123.

Do I need to expose port 8123 to the internet?

No, you should never expose port 8123 directly to the internet. By using Nginx as a reverse proxy, you keep the internal port hidden behind your domain name. This adds a layer of security and allows you to manage SSL certificates centrally through Nginx rather than on the guest.

How do I handle multiple Home Assistant instances?

You can run multiple instances by creating separate server blocks in Nginx, each with a different server name or subdomain. Each block will point to a different internal IP address or port for the respective Home Assistant instance. Ensure that each instance has a unique base_url configured internally.

Can I use HTTP instead of HTTPS?

While technically possible, using HTTP is strongly discouraged due to security risks. Home Assistant sends sensitive data including credentials and device states. Without encryption, this data can be intercepted by anyone on the network path. Always configure SSL/TLS for production or remote access setups.

What if my WebSocket connections drop frequently?

Frequent drops often indicate missing or incorrect WebSocket upgrade headers in the Nginx configuration. Double-check that proxy_set_header Upgrade $http_upgrade and Connection "upgrade" are present. Also, ensure that no intermediate firewalls are terminating idle connections too quickly.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More