This is an update on self hosting with cloudflared service using a raspberry pi 4. I was learning and making things more complicated than they already are. I’m pretty sure you don’t even need to run the NGINX engine either as once you install Jekyll and run it on localhost:4000 you’ll be able to use the cloudflared service to open up localhost:4000 instead of having to do it through nginx.
If y’all don’t know what I’m talking about feel free to read my first blog post on this matter: (hosting a personal blog) or don’t and proceed with this simple method. As I’m running on a raspberry pi I’ll be downloading via Linux:
Add Cloudflare’s package signing key:
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
Add Cloudflare’s apt repo to your apt repositories:
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
Update repositories and install cloudflared:
sudo apt-get update && sudo apt-get install cloudflared
Now, login to cloudflare’s website to authenticate; in terminal type:
cloudflared tunnel login
You should be automatically redirected to their website, if not just copy the link provided in the terminal and proceed to authenticate on there website.
in your .cloudflared
directory, create a config.yml file using any text editor. This file will configure the tunnel to route traffic from a given origin to the [hostname] of your choice.
I just used the in-terminal editor (cd) change directory to .cloudflared nano config.yml
Since, we’re connecting our tunnel to a application like jekyll which runs on localhost:4000 go ahead in that config file type:
Now, we will route the traffic to your website.
cloudflared tunnel route dns [UUID or NAME] [hostname]
If I remember correctly I added the UUID, which was the one given to me when I created my tunnel followed by myyear.net. If not, I might of just did:
cloudflared tunnel route dns TUNNELNAME DOMAINNAME
Finally, run the tunnel:
cloudflared tunnel run [UUID or NAME]
Sources: Cloudflared tunnel service