With all the cloud solutions on the market, self hosting has become a hobby for the extra nerdy. Why bother with all the port forwarding, securty implications, ISPs, and reliability headaches that come with self hosting when I can just click a button on AWS? Well, cloud solutions aren’t always the answer. They incur monthly fees that in most cases are far more expensive long term for anyone looking to stake out their piece of the internet. This article will show you that it doesn’t have to be all that complicated or risky to self host and it could prove to be the right alternative for you and your project. I will take you through step by step, everything you need to get up and running with your own hosting solution on nothing more than a Raspberry Pi.
What are Argo Tunnels?
On the whole, Argo Tunnels create an encrypted tunnel between your server and the Cloudflare network using the `cloudflared` daemon. Because of this, users won’t directly connect to your server, instead they will connect via proxy trough Cloudflare’s network. This brings a few benefits worth mentioning.
1) There is no need to open any ports on your network. To the outside world and even your ISP, your server just looks like any other encrypted web traffic.
2) There is no need to create, buy or mange TLS certificates as `cloudflared` handles all of this for you.
3) Argo utilizes smart routing to speed up traffic latency. They claim up to 30%, which I can’t verify but, I can say it does make a noticeable difference.
4) You get a WAF and DDOS protection built in.
Setting up a Cloudflare account and/or Activating Tunnels
To get started you are going to need a Cloudflare account with Argo Tunnels enabled. To do this, login/register at Cloudflare. Follow the instructions to add your site if you haven’t done so already. This will include setting up the required DNS configuration for your domain and Cloudflare’s name servers. The on-boarding process should take you through everything you need to get that set up. Once you have that step complete, toggle on Argo under the Traffic tab. From here we can continue on our Pi.
Setting up Cloudflared on the Pi
Cloudflare already provides some great how-to’s when setting up Argo and I strongly suggest you check those out as you are getting set up. The notable thing lacking here is Raspberry Pi support. In order to get the `cloudflared` daemon running on your Pi, we are going to need to compile it ourselves. But, don’t worry, this whole application has been written in Go and the installation process couldn’t be easier.
$ sudo apt-get install golang$ go install github.com/cloudflare/cloudflared/cmd/cloudflared
Yep, that’s it. You should now be able to run the following:
$ cloudflared — versioncloudflared version 2020.5.0 (built 2020–05–06–0336 UTC)
The next step will be logging in with `cloudflared`:
$ cloudflared tunnel loginA browser window should have opened at the following URL:https://dash.cloudflare.com/argotunnel?callback=https%3A%2F%2Flogin.cloudflarewarp.com%XXXXXXX
You can copy-paste the link provided into your browser to complete the login process.
Now that we’ve go that out of the way, the only thing left to do is get it up and running against a service. Simply point `cloudflared` to the address and port of your local service and let the magic happen.
$ cloudflared — hostname test.softwaredev.tech http://localhost:8000
This will automaticly create a DNS entry for you and set up the necessary TLS certificates your clients will use to get that HTTPS goodness. You should now be able to access your services over the internet. Note that regardless of which port you provide to `cloudflared`, they will be mapped to the more web friendly `80` for HTTP and `443` for HTTPS.
You can also run cloudflared as a service to keep it persistent across reboots.
To ensure your users have a secure connection, you can set up an HTTP redirect. To enable HTTPS redirects from HTTP, look for “Always Use HTTPS” under SSL/TLS and Edge Certificates in your console.
And that’s about it. Self hosting made easy, affordable, and secure. This could be a great solution for anyone at home looking to self host and save some dollar bills.