I manage servers for many web apps on a private network. I wanted HTTPS on the internet without port forwarding or exposing my public IP. Cloudflare Tunnel solved this. It is free and takes about 10 minutes.
How it works: cloudflared runs on your server and makes an outbound connection to Cloudflare. Visitors hit Cloudflare, and traffic flows through the tunnel to your app. No inbound ports needed.
Setup:
install
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb
create tunnel
cloudflared tunnel login
cloudflared tunnel create my-tunnel
cloudflared tunnel route dns my-tunnel app.example.com
/etc/cloudflared/config.yml:
tunnel: my-tunnel
credentials-file: /etc/cloudflared/.json
ingress:
- hostname: app.example.com service: http://localhost:3000
- service: http_status:404
sudo cloudflared service install
sudo systemctl enable --now cloudflared
Quick tips:
Getting a 502? Your app is down or on the wrong port. Check ss -tulpn and pm2 list.
Keep apps on localhost only, so they are reachable only through the tunnel.
Use PM2 for Node apps so they survive crashes and reboots.
Protect admin panels with Cloudflare Access.
No open ports, hidden IP, free HTTPS. Try it.
About me: I am Pratik Mule, a Cloud Engineer and Linux Administrator (RHCSA) and founder of Nexvelor.
Portfolio: https://pratikmule127.github.io/
LinkedIn: www.linkedin.com/in/pratik-mule
Top comments (2)
Useful guide. Two additions from running tunnels. First, run a second cloudflared connector for the same tunnel on another host or container, so one crash or restart does not take every app offline. Second, the hidden IP only stays hidden if the origin never answered the internet before: old DNS records and scan history can still reveal it, so keep the host firewall on default-deny inbound instead of relying on the tunnel alone. Running cloudflared tunnel ingress validate before restarting also catches config typos.
Thanks Hritik, good tips. Will add the second connector and the firewall rule on my setup.