TLDR;

Moved the site you are looking from digital ocean droplet to home Raspberry Pi using cloudflare’s tunnel service. Watch two youtube videos referenced on how it is done.

Motivation

This website you’re checking out was made using Hugo.it’s just a basic static site hosted on a DigitalOcean droplet, which cost me around 3-4 dollars every month. I always thought spending more for a static site wasn’t worth it, as they could be hosted from various edge services or even my own home server However for free. When I first started this site on DigitalOcean, I had other things workloads running on Ditalocean, but over time i moved everyting from digitalovean to my own hommelab seutp, since I don’t have anything on DigitalOcean now, I decided to save money and use an old Raspberry Pi along with Cloudflare Tunnel to latest version of my site. Rest of the post is more of my notes, feel free to skip and just watch youtube videos to understand the same.

What you need

  • Raspberry Pi
  • Host Machine to setup (in my case my using my Mac to setup bootable USB)
  • Cloudflare account
  • a domain ( i have a domain from namecheap)

Setup Raspberry Pi

  • Use https://www.raspberrypi.com/software/ software to easily setup bootable USB
  • Once you select the image and storage like below, make sure you click on the advance image customization to enable SSH. This will help connect to Pi in a headless way out of the box.

Setup docker

Login to your docker machine and run folloing commnads to setup docker

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose
sudo usermod -aG docker $USER
newgrp docker

Setup Nginx

As you can see from below docker commnad, i just ran simple nginx with volume where my hugo public directore is refferenced. Nothing fancy!

docker run -it --rm -d -p 8080:80 --name web -v /home/msio/nginx-html:/usr/share/nginx/html nginx

Setup Cloudflare

  • Create an account with cloudflare. The Tunnel service is a free feature that we can use to securely direct traffic to the Raspberry Pi.
  • From the Dashboard, click on Add Site and input the site you want Cloudflare to manage.
  • On the next page, choose the free account option and proceed to the next step where you can manage your DNS records. I recommend removing all records and moving on to the next step.
  • Finally, you’ll find Cloudflare’s nameserver details; be sure to take note of them.
  • Now, log in to your Namecheap or any other hosting service and update your nameservers accordingly

Setup tunnel

  • Go back to bashboard on cloudfalre home page. From there using Zero Trust -> Access -> Tunnel
  • In the subsequent screen, you’ll be prompted to input a name for your tunnel configuration. After providing a name, save the tunnel configuration. Upon saving, you’ll encounter options for selecting your preferred method of creating a tunnel. In my opinion, opting for Docker to execute the tunnel appears to be the more straightforward approach.
docker run --platform linux/arm/v7 cloudflare/cloudflared:latest tunnel --no-autoupdate run --token {add you token from cloudflaser}

References

Setup Pi

Cloudflare tunnel