This guide walks you through securely exposing self-hosted applications (like Home Assistant, Nextcloud, or a personal wiki) to the internet. You’ll learn the recommended methods—reverse proxy with TLS, authentication, and firewall rules—so your services are accessible remotely without opening risky ports or exposing your home network to attackers.
What You’ll Need
- A self-hosted app already running on your local network (e.g., on a Raspberry Pi, NAS, or old PC).
- A domain name (or a subdomain) that you control—free options like DuckDNS work.
- Basic familiarity with your router’s admin panel and command line.
- Optional but recommended: a static IP or dynamic DNS service for consistent access.
Step-by-Step
- Assign a static local IP to your server. Log into your router’s DHCP settings and reserve an IP address (e.g., 192.168.1.100) for your server’s MAC address. This ensures the IP doesn’t change after a reboot.
- Set up a reverse proxy (like Nginx or Caddy). Install the proxy on a dedicated machine or the same server. For Nginx, create a site config that forwards requests from a subdomain (e.g., app.yourdomain.com) to your app’s local IP and port (e.g., 192.168.1.100:8080). Caddy simplifies this with automatic HTTPS.
- Enable TLS/HTTPS. Use Let’s Encrypt to get a free SSL certificate. With Caddy, it’s automatic. With Nginx, install Certbot and run
certbot --nginxto obtain and configure the certificate. - Set up authentication. If your app doesn’t have its own login, add a layer like Basic Auth in Nginx (using
htpasswd) or use a single sign-on solution like Authelia or Authentik. This prevents unauthorized access even if the app is exposed. - Configure your firewall. On your server, allow only ports 80 (HTTP) and 443 (HTTPS) from the internet. Block all other inbound ports. On your router, do NOT forward port 22 (SSH) or any other service—only forward 80 and 443 to your reverse proxy.
- Set up port forwarding on your router. Forward external ports 80 and 443 to your reverse proxy’s local IP (e.g., 192.168.1.100:80 and 192.168.1.100:443). This is the only traffic that reaches your network.
- Update DNS records. Point your domain’s A record to your public IP address. If you have a dynamic IP, use a dynamic DNS service like DuckDNS or a script to update the record automatically.
- Test locally first. From your local network, visit
https://app.yourdomain.com. If it works, the proxy and TLS are correct. Then test from an external network (e.g., your phone’s cellular data) to confirm the port forwarding works. - Harden the proxy. Disable directory listing, set proper security headers (like
X-Frame-OptionsandContent-Security-Policy), and enable rate limiting to prevent brute-force attacks. - Monitor and update. Regularly update your OS, proxy, and apps. Consider setting up fail2ban to block repeated failed login attempts.
Common Mistakes
- Forwarding ports directly to the app without a reverse proxy—this exposes the app’s raw traffic and often its internal authentication.
- Using HTTP instead of HTTPS—passwords and data are sent in plain text.
- Forgetting to set a strong password for your app—many default credentials are publicly known.
- Opening too many ports (like SSH or database ports) to the internet—this invites brute-force attacks.
- Not setting up a firewall on the server itself—relying only on the router’s port forwarding.
- Ignoring dynamic IP changes—your domain stops resolving correctly.
Tips
- Use a separate subdomain for each app (e.g., nextcloud.example.com, homeassistant.example.com) to isolate failures.
- Consider using a VPN (like WireGuard or Tailscale) for personal access instead of exposing apps publicly—it’s safer and simpler.
- If you must expose an app, run it in a Docker container with a non-root user and read-only filesystem where possible.
- Enable two-factor authentication (2FA) on any app that supports it.
- Regularly check logs for suspicious activity (e.g., failed logins, unusual requests).
- Use a cloudflare tunnel or a similar service if you don’t want to open any ports on your router—this hides your home IP.
Troubleshooting
- Site doesn’t load externally: Verify port forwarding is correct (use an online port checker). Check that your public IP hasn’t changed. Confirm the reverse proxy is listening on 80/443.
- Certificate errors: Ensure your domain resolves to the correct IP. If using Let’s Encrypt, check that ports 80/443 are reachable from the internet during issuance.
- App loads but shows a blank page: Check the proxy logs for errors. Ensure the proxy’s
proxy_passpoints to the correct local IP and port. Some apps need WebSocket support—enableUpgradeheaders in Nginx. - Slow performance: Enable gzip compression in the proxy and consider caching static assets.
- Cannot access from local network but works externally (NAT loopback issue): Some routers don’t support hairpin NAT. Add a local DNS override that resolves your domain to the server’s local IP.
- Port 80/443 already in use: If another service uses those ports, either stop it or change the proxy’s listen ports and forward the corresponding external ports.
Frequently Asked Questions
Is it safe to expose self-hosted apps to the internet?
It can be safe if you follow best practices: use a reverse proxy with HTTPS, strong authentication, and keep software updated. However, any internet-facing service increases risk, so consider a VPN for personal use.
Do I need a static IP?
No, you can use dynamic DNS services like DuckDNS or No-IP to map a domain to your changing IP. Many routers have built-in DDNS clients.
Can I use a free domain?
Yes, services like DuckDNS offer free subdomains. For a custom domain, you can buy one cheaply or use free options like Freenom (though availability varies).
What’s the difference between a reverse proxy and a VPN?
A reverse proxy exposes specific services to the internet, while a VPN creates a secure tunnel to your network, allowing access to all services without exposing them publicly. VPN is generally more secure.
How do I protect against brute-force attacks?
Use strong passwords, enable 2FA, set up fail2ban to block IPs after multiple failures, and limit login attempts in your app or proxy.
Should I expose the app directly on port 80/443?
No, always use a reverse proxy. It handles TLS, adds security headers, and allows you to host multiple apps on the same ports.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix Device Manager Not Opening in Windows 11
- How to Pause Snapchat Location
- System Restore Points Missing in Windows? Fixes
- Loop Nature Ambience Videos with FFmpeg on Ubuntu
- Install League of Legends on Linux: Full Guide
- Fix Error 0x80070001: Causes & Solutions