Self-Host a Website Safely with Raspberry Pi & Cloudflare Tunnel
I’ve always loved the idea of hosting my own website at home, but messing with router settings and exposing my IP? No thanks. That’s why I gave Cloudflare Tunnel a shot with my Raspberry Pi. Honestly, it’s way easier and safer than I expected. Let me show you how it works!
A website can be safely hosted at home on a Raspberry Pi by running a local web server and exposing it via a Cloudflare Tunnel. This establishes an encrypted connection to Cloudflare’s network, enabling global access without opening router ports or exposing the home IP address.
In this tutorial, I will guide you through every step, from installing the necessary software to configuring your website. You’re free to host whatever you like: whether it’s a simple WordPress blog or a full-featured e-commerce system, it’s the same process.
If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!
Overview of Self-Hosting with Cloudflare Tunnel
When we talk about self-hosting, we mean running a website directly on your Raspberry Pi—without relying on online hosting services to make it accessible to others. Normally, for users to reach your site, you’d need to host it on platforms like GoDaddy, Namecheap, or other traditional web hosts.
With self-hosting, you take full control and serve the site straight from your own hardware. In the past, I personally relied on Ngrok. Ngrok works well and is great for quick demos, but its main drawback is that it creates a direct external tunnel to your device. This behaves much like an exposed port, which can increase security risks – especially if you plan to host something long-term.
But now I’ve discovered Cloudflare Tunnel, which I think is a much better solution.
Why Cloudflare Tunnel Changes the Game
To better understand how all this works, think of Cloudflare as the “middleman” that keeps your Raspberry Pi hidden from the public internet.
Download the free PDF, keep it open, and stop wasting time on Google.
Download now
And this is the most interesting bit. Cloudflare Tunnel does not require router port forwarding at all. You don’t have to open port 80, port 443, or any other port on your home network. Your Raspberry Pi stays safely behind your router and firewall the entire time.
Instead, Cloudflare creates a secure, encrypted tunnel from your Raspberry Pi straight into its global network. Your device stays safely behind your firewall the entire time.
Members get an ad-free version of every guide, plus exclusive project support.
Join the Community | Sign In

So here’s what actually happens: when someone visits your site (like testsite.raspberrytips.com), their request doesn’t come directly to your house. It first goes through Cloudflare’s network. Cloudflare then sends that request down the encrypted tunnel to your Raspberry Pi.
Your Raspberry Pi processes the request, sends the response back through the same secure tunnel, and Cloudflare delivers it to the visitor. The whole process is seamless, fast, and completely avoids the risks of exposing your home IP or opening any router ports.
Hardware Requirements
Here’s the hardware you will need for this project:
- Raspberry Pi board: The model you choose depends on how demanding your website is. If your project requires more processing power, like running WordPress, handling heavy traffic, or serving dynamic content, then a Raspberry Pi 4 or Raspberry Pi 5 is highly recommended.
For lighter projects or simple static websites, older models such as the Raspberry Pi 3B+ or even the Raspberry Pi Zero will still work just fine. - MicroSD card: You’ll need a microSD card that’s at least 8GB, although the ideal size depends on the operating system you plan to install.
- Reliable internet connection: You’ll definitely need a stable internet connection with a consistent upload speed. Since users will be accessing your site remotely, a weak or unstable upload connection can slow down or make your site unreachable.
- Optional peripherals: If you are not accessing your Raspberry Pi remotely, either via SSH or VNC, then you will need a keyboard, mouse, and HDMI monitor for setup.
Software Requirements
- Operating system installed: For this project, you’re not limited to Raspberry Pi OS; you can use any Linux-based distribution that supports ARM processors.
- Cloudflared (Cloudflare Tunnel client): The software that connects your Raspberry Pi to Cloudflare’s network. It creates a secure tunnel that lets users access your site without exposing your home IP.
- Web server software (e.g., Apache, Nginx): You’ll need a web server to serve your website files. Apache is beginner-friendly, while Nginx is lightweight and great for performance on low-power devices.
- Your website platform (e.g., WordPress, static site, or custom app): This depends on what you want to host. It can be something simple like a static HTML site, a full WordPress installation, or even a custom app you built with Python, Node.js, or React.
Set Up Your Website
Before we configure Cloudflare Tunnel, it’s important to understand what type of website you’re running and which port it uses. Cloudflare needs this information so it knows exactly where to forward traffic on your Raspberry Pi.
There are generally two common scenarios:
Scenario 1: You’re Using WordPress (Port 80)
If you installed WordPress on your Raspberry Pi, then your site is likely being served by Apache or Nginx, usually from: /var/www/html
Download the free PDF, keep it open, and stop wasting time on Google.
Download now
In this case, your web server runs on port 80, meaning your Raspberry Pi serves the site locally at:http://localhost/80
And if you want a quick refresher on how Apache, PHP, and MySQL all work together on the Raspberry Pi, you can go through our full LAMP server setup guide – it walks you through everything step by step.

So when you set up your Cloudflare Tunnel, you’ll need to point it to port 80, since that’s where WordPress is actually running.
Scenario 2: You Built a Custom Website or Web App (Different Port)
If you developed your own site or app, maybe using Node.js, Python, or a frontend dev server like Vite, React, or Flask, your application may run on a completely different port, such as 3000, 5000, 5173, or any other port you configured.

In that situation, your Cloudflare Tunnel should point to that exact port, so incoming traffic is routed correctly to your application.
Check this: 7 Surprising Uses for a Raspberry Pi
Tip: For this tutorial, I’m keeping things simple. I created a basic HTML/CSS website and placed it in the /var/www/html directory, which means it runs on port 80.
Create a Cloudflare Account
Download the free PDF, keep it open, and stop wasting time on Google.
Download now
Up to this point, I assume that you have your site up and running on your Raspberry Pi. Now, let’s dive into setting up Cloudflare on your Raspberry Pi.
The first thing you need to do is go to the Cloudflare official website, create an account if you don’t have one, and add your domain. Now I will be honest about this step; it is pretty easy, but navigating the different menus on Cloudflare can sometimes be confusing. So let me break it down step-by-step.
- Create an account with Cloudflare. Here you have several options to choose from. That includes Google, Apple, Email, and even GitHub.
- After logging in, click the ADD button in the top menu as shown in the image below.
- After adding your domain, Cloudflare will show radio buttons asking how you want to import your DNS records. From experience, I recommend choosing “Quick scan for DNS records.” It’s the suggested option and will save you a lot of time.

Once done, click “Continue” at the bottom. - In the next step, select the pricing plan you want to use. For this tutorial, I suggest starting with the “Free Pan” and upgrading later.
- Next, you will come across a page with a step-by-step guide on how to update your domain nameservers to point to those provided by Cloudflare. By now, you will actually notice an orange notification at the top with the message “invalid nameservers”.

To fix this error, follow the steps provided, and once done, click the “Check Nameserves Now” at the bottom.
Tip: Cloudflare assigns unique nameservers to every domain. Always use the exact nameservers shown in your Cloudflare setup instructions. - After you update your nameservers, Cloudflare will verify the change. Once everything is correct, you’ll see the status “Active” at the top, just like in the image below.

That’s it, you’ve successfully added your domain to Cloudflare. Now let’s return to the Raspberry Pi to install and configure the Cloudflare Tunnel.
Install and Configure Cloudflare Tunnel
Cloudflare Tunnel creates a secure, encrypted link from your Raspberry Pi to Cloudflare, enabling users to access your self-hosted site without opening any ports on the local network.
In this section, I will give you a step-by-step guide on installing and configuring Cloudflare tunnel on your Raspberry Pi.
- First, download the latest Cloudflared .deb package for Raspberry Pi by running:
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm.deb
- Once the download is complete, install the package with dpkg so your Raspberry Pi can run Cloudflared:
sudo dpkg -i cloudflared-linux-arm.deb - Check that Cloudflared is installed correctly and see the version to confirm everything is working:
cloudflared -v
- Next, log in to your Cloudflare account from the Raspberry Pi to link it with your Cloudflare dashboard. Run the command below:
cloudflared loginThis will display a URL in your terminal. Open that link in your browser to connect the domain you added to Cloudflare.
In your browser, you’ll be prompted to choose the domain you want to link. Select your domain, and a pop-up will appear asking you to “Authorize.” Approve it to complete the connection.
If everything was okay and you didn’t experience any errors, you should see a “success” pop-up similar to the image below.
Once done, Cloudflare will generate a certificate for you, which will be added to /home/username/.cloudflared/cert.pem. - Next, you need to create a tunnel for your website by running the command below. Ensure you use a unique name in case another tunnel is already running.
cloudflared tunnel create your-tunnel-nameFor example, in my case, I will use:cloudflared tunnel create my-rasp-site
This will create a new tunnel with a unique ID. Please copy this ID and paste it somewhere, as we will need it later.
- Next, you will create a configuration file to manage the tunnel. Now this is where we will add things like port numbers the site is using, and even domains and sub-domains. Execute the command below.
sudo nano ~/.cloudflared/config.yml
Copy and paste the details below. Please remember to change some of the details accordingly. Like the home directory, tunnel ID, domain name, and service port.
tunnel: 74ec7ff1-dcc1-4b53-8788-a6a2e1480da9
credentials-file: /home/pat/.cloudflared/74ec7ff1-dcc1-4b53-8788-a6a2e1480da9.json
ingress:
- hostname: your-domain.com
service: http://localhost:80
- service: http_status:404
- Next, you will create the DNS entry that links your tunnel to your domain by running the command below:
cloudflared tunnel route dns mywpsite yourdomain.com
Cloudflared will automatically create the correct CNAME record for you—no manual DNS editing needed.
- Once done, start the tunnel using the command below:
cloudflared tunnel run mywpsite
Unless the tunnel stops due to an unexpected error, everything should now be running smoothly, and you’re good to go.
You might also like: 25 project ideas you can try at home with Raspberry Pi
Test Your Website with Cloudflare Tunnel
Now that your tunnel is up and running, it’s time to make sure everything is working as expected. Open your browser and navigate to the domain or subdomain you linked to your Raspberry Pi.
In my case, you can see below that my site loaded successfully, confirming the tunnel is working perfectly.

Download the free PDF, keep it open, and stop wasting time on Google.
Download now
If everything was configured correctly, you should see your website load just like it would on a normal server. This confirms that the Cloudflare Tunnel is successfully routing traffic from the internet to your Raspberry Pi.
If the site doesn’t load, double-check your config.yml, ensure the tunnel is running, and verify that the correct ports are open on your Raspberry Pi.
I believe you have everything running up to this point. Cloudflare Tunnel makes it easy to expose your Raspberry Pi-hosted website to the internet. Once your tunnel is up, your site is accessible from anywhere while staying protected behind Cloudflare’s network.
Keep in mind, this setup is ideal for testing, personal projects, or learning purposes, but it’s not recommended for production websites or high-traffic sites, as a Raspberry Pi and home network may not handle heavy traffic reliably.
Prefer videos over reading? The RaspberryTips Community members get exclusive video lessons every month. Join now and watch them all right away. Get instant access.
FAQ
Will my site stay online if my Raspberry Pi turns off?
No. Since your Raspberry Pi is the server hosting your site, if it powers off or loses connectivity, the site will go offline. The tunnel relies on your Pi being up and connected to the internet.
Do I need a static IP address to self-host a website with Cloudflare Tunnel?
No. One of the advantages of Cloudflare Tunnel is that it works even with a dynamic IP. Cloudflare handles the external routing, so you don’t need to worry about changing IP addresses at home.
Can I use Cloudflare Tunnel for multiple websites or subdomains?
Yes. You can configure the tunnel to route traffic to multiple sites or subdomains by adding additional hostname entries in your config.yml. Each site or subdomain can have its own local service address on your Raspberry Pi.
Whenever you’re ready, here are other ways I can help you:
Test Your Raspberry Pi Level (Free): Not sure why everything takes so long on your Raspberry Pi? Take this free 3-minute assessment and see what’s causing the problems.
The RaspberryTips Community: Need help or want to discuss your Raspberry Pi projects with others who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct help.
Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.
You can also find all my recommendations for tools and hardware on this page.
