
Self-hosting WordPress is powerful, but opening router ports to expose it to the internet is risky. Cloudflare Tunnel for WordPress solves this: it publishes your site through an outbound-only connection, so your server never accepts inbound traffic at all. This guide shows you how to set it up, fix the common HTTPS redirect loop, and lock wp-admin behind Cloudflare Access — all free.
What Is Cloudflare Tunnel?
Cloudflare Tunnel connects your server to Cloudflare’s global network using a small connector called cloudflared. Instead of your router forwarding port 80 or 443, cloudflared makes an outbound connection to Cloudflare. Visitors reach your site through Cloudflare’s edge, which passes each request down the tunnel. The result: no port forwarding, no static IP, no firewall rules, and free HTTPS — while your origin server stays invisible to the public internet.
Why Use Cloudflare Tunnel for WordPress?
Every open port on your server is a target for bots. Cloudflare Tunnel closes them all:
- No open ports: your server makes only outbound connections, so port scanners find nothing.
- Free SSL: Cloudflare terminates TLS at the edge, so visitors always see HTTPS.
- DDoS protection: malicious traffic is absorbed by Cloudflare before it reaches your server.
- Works anywhere: a home server, a Raspberry Pi, or a VPS — even behind CGNAT or IPv6-only networks where port forwarding fails.
If you already use Cloudflare for your domain, adding a tunnel is the natural next step. Pair it with the best Cloudflare settings for WordPress.
What You Need Before You Start
- A free Cloudflare account with your domain on Cloudflare DNS.
- A running WordPress install — VPS, home server, or Raspberry Pi.
- SSH access to the WordPress machine to install cloudflared.
How to Set Up Cloudflare Tunnel for WordPress
Step 1: Create the Tunnel in Zero Trust
Open Zero Trust → Networks → Tunnels, click Create a tunnel, choose the Cloudflared type, and name it wordpress-tunnel. Cloudflare shows an install command with a long token — copy just the token.
Step 2: Install cloudflared on Your Server
On Debian or Ubuntu, download the package and install it:
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb
On macOS use Homebrew; on Windows use winget install --id Cloudflare.cloudflared.
Step 3: Run the Tunnel with Your Token
Start the connector with the token from step 1:
cloudflared tunnel run --token YOUR_TUNNEL_TOKEN
For a permanent setup, run cloudflared as a system service or a Docker container.
Step 4: Add a Public Hostname Route
Back in the Zero Trust dashboard, open your tunnel and add a public hostname: your domain, for example yourdomain.com, with the service set to HTTP pointing at WordPress — usually localhost:80, or wordpress:80 in Docker Compose. Cloudflare creates the DNS record for you.

Step 5: Fix the HTTPS Redirect Loop
Cloudflare terminates TLS at the edge, so WordPress only sees plain HTTP — and without a fix, it can redirect visitors in an endless loop. Add this to wp-config.php, before “That’s all, stop editing!”:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { $_SERVER['HTTPS'] = 'on'; }
Then set SSL mode to Full (Strict) and enable Automatic HTTPS Rewrites.
Step 6: Test Your Site
Visit your domain. Your WordPress site should load over HTTPS with a valid certificate, even though no port is open. In the dashboard under Zero Trust → Tunnels, your tunnel should show as healthy.
Lock Down wp-admin with Cloudflare Access
A tunnel hides your server, but your login page is still public. In the Zero Trust dashboard, create an Access application for yourdomain.com/wp-admin allowing only your email address. Anyone visiting wp-login.php must first pass an email one-time code — bots never even see the login form. Add the same rule for yourdomain.com/xmlrpc.php. Our Cloudflare cache rules guide for WordPress keeps the site fast as well as secure.
November 2026 Update: URL Normalization
Cloudflare shipped a change in November 2026 worth knowing. From cloudflared 2026.10.0, the tunnel can normalize URLs before matching ingress rules, and 2026.11.0 (November 12, 2026) extends it to semicolon-delimited path parameters. It is opt-in today and becomes the default in new releases from February 8, 2027. If your ingress rules require Cloudflare Access validation, test the new behaviour on a staging tunnel first. Normalization only affects rule matching — WordPress still receives the original path, so permalinks keep working.
Common Problems and Fixes
- Too many redirects: SSL mode is Flexible instead of Full, or the wp-config.php snippet above is missing.
- Error 1033: the tunnel token is wrong or cloudflared is not running. Restart it and check the tunnel status.
- Broken images: mixed content. Enable Automatic HTTPS Rewrites, or fix URLs in the database from http to https.
Final Thoughts
Cloudflare Tunnel is the safest way to put a self-hosted WordPress site on the internet: free HTTPS, DDoS protection, and zero open ports, set up in under half an hour. Add Cloudflare Access in front of wp-admin and keep cloudflared updated. Explore more free utilities in the KamiWeb tools library.
Frequently Asked Questions
Is Cloudflare Tunnel really free?
Yes — tunnels, hostname routing, and basic Access rules are all free.
Can I use Cloudflare Tunnel with shared hosting?
Usually not — shared hosts do not give terminal access to install cloudflared. It works best on a VPS, a dedicated server, a home server, or a Raspberry Pi.
Does Cloudflare Tunnel slow down WordPress?
Barely. Traffic routes through Cloudflare’s nearest edge location, adding only a few milliseconds, and caching usually makes the site faster overall.
Do I still need a security plugin?
Yes. The tunnel hides your server and Access protects logins, but a security plugin still guards against plugin vulnerabilities, malware, and bad uploads.
