How to Use Cloudflare Tunnel (cloudflared) to Expose Web Apps Without Opening Firewall Ports
Exposing a staging WordPress site, internal dashboard, or home-lab service to the internet traditionally means opening ports 80 and 443 on your firewall, managing port forwarding, and exposing your server’s real IP address to automated vulnerability scanners. Cloudflare Tunnel flips that model around: a lightweight daemon (cloudflared) running on your server opens outbound-only encrypted connections to Cloudflare’s global edge, so your origin firewall can stay completely closed to inbound traffic.
Editorial illustration: cloudflared establishes outbound tunnels to Cloudflare, keeping ports 80 and 443 closed on your server firewall.
Summary
- Outbound-only architecture:
cloudflaredconnects outward to Cloudflare’s nearest data centers and routes requests locally (for example, tohttp://localhost:8080), eliminating the need for open inbound HTTP/HTTPS ports or a static public IP. - Remotely-managed vs. locally-managed: Per Cloudflare’s Tunnel documentation and Cloudflare One Tunnel docs, Cloudflare recommends remotely-managed tunnels (configured in the Zero Trust dashboard, API, or Terraform) for most production and staging setups, while locally-managed tunnels (
cloudflared tunnel create <NAME>) fit local dev or legacy config-file workflows. - Always pair a Cloudflare Tunnel with Cloudflare Access for staging or internal admin apps—remember that a tunnel connects traffic to your origin, whereas Access authenticates who is allowed through.
- Install
cloudflaredas a system service (systemdon Linux) so tunnels survive server reboots automatically.
How Cloudflare Tunnel differs from standard Cloudflare DNS proxying
With a standard orange-clouded A record:
- Your server still listens publicly on port
443and answers requests from anyone who discovers your origin IP (via historical DNS records or IPv4 range scans). - You must maintain firewall allowlists for Cloudflare IP ranges and manage origin TLS certificates.
With Cloudflare Tunnel:
- Cloudflare creates a DNS
CNAMEpointing to<tunnel-id>.cfargotunnel.com. cloudflaredinitiates outbound connections over QUIC/HTTP2 from inside your server or private VPC.- You can block all inbound traffic on ports
80and443at the VPS firewall—only keeping SSH (or moving SSH behind Access too) open if needed.
Step-by-step: Set up a remotely-managed tunnel
1. Create the tunnel in Cloudflare Zero Trust
In the Cloudflare dashboard, go to Zero Trust > Networks > Tunnels and select Create a tunnel:
- Choose Cloudflared as the connector type.
- Name the tunnel clearly (for example,
staging-web-sg01). - Copy the OS-specific
cloudflared service install <token>command shown in the dashboard.
2. Install and run cloudflared as a service on your server
Run the provided install command on your Linux VPS (or run the official cloudflare/cloudflared Docker container with --no-autoupdate tunnel --token ...). Running cloudflared as a managed service ensures it restarts automatically after kernel updates or reboots.
3. Add a Published Application Route
In the tunnel’s Public Hostname tab:
- Subdomain & Domain:
staging.example.com - Service Type:
HTTP - URL:
localhost:8080(ornginx:80inside Docker networks)
Cloudflare automatically creates the CNAME record for staging.example.com and handles public HTTPS termination at the edge.
4. Gate private apps with Cloudflare Access and close inbound ports
A tunnel alone makes staging.example.com reachable by anyone on the internet! Immediately add a Zero Trust Access policy if the service is private (see our guide on protecting staging sites and admin panels with Cloudflare Access), and verify your VPS firewall (ufw status or cloud security group) drops inbound 80 and 443. For public sites behind the tunnel, pair it with Cloudflare WAF rate limiting and Cloudflare Transform Rules security headers.
Common mistakes
- Running
cloudflared tunnel runinside an interactive SSH terminal instead of a system service. The moment your SSH session disconnects, your site goes offline. Always install it as asystemdservice or managed container. - Assuming a Cloudflare Tunnel provides authentication by itself. Tunnels replace open ports, not login walls—add Cloudflare Access or app authentication for any non-public service.
- Leaving an old
Arecord or direct port443firewall rule active after migrating. Remove old public origin firewall rules so attackers cannot bypass Cloudflare by connecting to the old IP directly. - Forgetting to set
Hostheaders or reverse-proxy trusted headers (X-Forwarded-Proto) in WordPress/Drupal. Becausecloudflaredoften talks tohttp://localhost:80over loopback, make sure your CMS recognizes HTTPS viaX-Forwarded-Protoso it does not trigger infinitehttp -> httpsredirect loops.
Why this matters
Every open port on a cloud VPS attracts automated scanners within minutes of boot. Switching staging and internal origins to outbound-only Cloudflare Tunnels shrinks your public attack surface to zero open web ports while keeping HTTPS and Zero Trust controls centralized at Cloudflare’s edge.
My Take
For any new staging VPS, internal dashboard, or self-hosted admin tool, skip opening ports 80 and 443 completely—install cloudflared as a remotely-managed tunnel and put Cloudflare Access in front of it. You get automatic edge TLS, zero origin IP exposure, and clean dashboard routing in under ten minutes.
Conclusion
Create a remotely-managed Cloudflare Tunnel in Zero Trust, run cloudflared as a system service pointing to localhost, close inbound 80/443 ports on your host firewall, and attach a Cloudflare Access policy before sharing the URL.