
Expose a Local Next.js App to the World with Cloudflare Tunnel
TL;DR:
- Cloudflare Tunnel turns your localhost into a secure public URL without exposing your IP or opening router ports. Cloudflare Tunnel docs
- Quick Tunnel gives a one-time, temporary URL; for permanent access, point a subdomain at Cloudflare and configure a config.yml. Quick Tunnels docs
- Install cloudflared via Homebrew, Winget, or the Linux package, then cloudflared tunnel login. Downloads docs
- Create a tunnel, edit the config file, route DNS, and run. Useful commands docs
- DNS changes can take minutes to hours; test with TryCloudflare first.
Table of Contents
Why this matters
I’ve been stuck in the same loop: my dev server runs on localhost:3000, I want to show a demo to a client, but port forwarding feels like a chore, the VPN route is fragile, and renting a VPS feels like overkill. Cloudflare Tunnel solves all of that in one go. It gives me a public HTTPS URL, keeps my home IP hidden, and works on any framework – Next.js, Node, Django, Laravel, React, or plain HTML. Cloudflare Tunnel docs
Core concepts
- What is Cloudflare Tunnel?
It’s a lightweight daemon (cloudflared) that opens an outbound TLS connection from your machine to Cloudflare’s edge. No port is opened on your router, no public IP is exposed. Cloudflare Tunnel docs - Quick Tunnel vs. Permanent Tunnel
Quick Tunnel (cloudflared tunnel –url http://localhost:3000) gives you a random *.trycloudflare.com URL that changes each time you start it. It’s perfect for quick sharing. Permanent Tunnel requires a Cloudflare-registered domain, DNS records, and a config.yml. Quick Tunnels docs - config.yml
The config lives in ~/.cloudflare/config.yml. It must contain:The file is YAML; the credentials file is JSON. Configuration file docstunnel: 1ed88140 credentials-file: /home/user/.cloudflare/credentials.json ingress: - hostname: demo.example.com service: https://localhost:3000 - hostname: "*" service: http_status: 404 - DNS
Cloudflare must be the authoritative nameserver for your domain, and the subdomain must point to the tunnel. DNS propagation can take 5–10 min, 1–2 h, or up to 24 h. DNS propagation community post
| Feature | Quick Tunnel | Cloudflare Tunnel | VPS Hosting |
|---|---|---|---|
| Setup Time | Instant | Minutes | Hours |
| Cost | Free | Free (free plan) | Paid |
| Persistence | Temporary | Permanent | Permanent |
| Security | Outbound only, no IP exposed | Outbound only, no IP exposed | Exposes IP, port open |
| Use Case | Quick sharing | Demos, staging, internal tools | Production workloads |
| Limitation | URL changes on restart | Requires Cloudflare account & DNS | Port forwarding & cost |
How to apply it
- Install cloudflared
- macOS: brew install cloudflared Homebrew formula
- Windows: winget install –id Cloudflare.cloudflared Winget package
- Linux: download the .deb/.rpm or use the Cloudflare package repo. Downloads docs
- AuthenticateA browser opens to sign in. Useful commands docs
cloudflared tunnel login - Create a tunnelThe command outputs a tunnel ID and writes a credentials file to ~/.cloudflare/credentials.json. Useful commands docs
cloudflared tunnel create my-tunnel - Configure config.yml
Edit the file to map your domain to the local port, as shown above. The tunnel: line is the hex ID from step 3. - Add DNS recordThis creates a CNAME that points the subdomain to the tunnel. Useful commands docs
cloudflared tunnel route dns my-tunnel demo.example.com - Run the tunnelThe tunnel stays alive as long as your local server runs. If the machine disconnects, the public URL disappears. Cloudflare Tunnel docs
cloudflared tunnel --config ~/.cloudflare/config.yml run my-tunnel - Verify
Openhttps://demo.example.comin a browser. You should see your app. If you change the config, restart the tunnel.
Pitfalls & edge cases
- Local server stops → tunnel stops – I’ve had to keep my laptop awake during demos.
- DNS not propagated yet – Use TryCloudflare first to make sure the tunnel works before updating the real domain.
- Ingress rule typo – A missing hostname: line triggers a 404 for all traffic.
- Wrong name-servers – If your domain still points to GoDaddy, Cloudflare won’t see the DNS changes.
- Quick Tunnel not for production – The URL changes each restart, so never point a client’s real device to it.
- Free plan limits – The free plan supports unlimited tunnels but has rate limits; for high-traffic staging, consider the paid plan.
Quick FAQ
- How long does DNS propagation take?
It can be as quick as 5–10 min, but up to 1–2 h or 24 h in worst cases. DNS propagation community post - Can I use my own subdomain on GoDaddy?
Yes, but you must change GoDaddy’s nameservers to Cloudflare’s and then add the subdomain in Cloudflare’s DNS panel. Cloudflare Tunnel docs - Does Cloudflare Tunnel reveal my public IP?
No, it only opens an outbound TLS connection; your IP stays hidden. Cloudflare Tunnel docs - What if my laptop loses power during a demo?
The tunnel will close and the URL will stop working. Keep the machine on or use a more reliable host. - Can I run the tunnel as a Linux service?
Yes, see Cloudflare’s guide on configuring cloudflared as a systemd service. Downloads docs
Conclusion
Cloudflare Tunnel is a free, secure, and framework-agnostic way to expose any local web app to the internet without fiddling with routers or paying for a VPS. Follow the steps above, test with TryCloudflare, and you’ll have a permanent, stable URL in minutes. It’s perfect for developers, product teams, and dev-ops who need quick demos, internal staging, or testing environments. If you’re running a production service, consider a dedicated host; but for all other cases, Cloudflare Tunnel is a win.
References
- Cloudflare Tunnel docs – https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/
- Quick Tunnels docs – https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/trycloudflare/
- Useful commands docs – https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/tunnel-useful-commands/
- Configuration file docs – https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/
- Downloads docs – https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/
- Homebrew formula – https://formulae.brew.sh/formula/cloudflared
- Winget package – https://winget.run/pkg/Cloudflare/cloudflared
- DNS propagation community post – https://community.cloudflare.com/t/dns-records-are-not-propagated/609216
- Quick Tunnels blog – https://blog.cloudflare.com/quick-tunnels-anytime-anywhere/