Creating a cloudflare tunnel for pubilc access of self-hosted applications
As a technologist passionate about building robust systems, I am deeply engaged with DevOps, cloud-native technologies, and automation. My technical journey is centered on a deep dive into Golang, where I explore everything from concurrency to building system tools. I am also proficient in Python, applying it to machine learning and data science projects. From architecting Kubernetes clusters to exploring cybersecurity principles and the fundamentals of self-improvement, I am a lifelong learner constantly seeking new challenges. This blog is where I document my projects and share insights from the ever-evolving world of technology.
The What?
This is a simple tutorial where i will be explaining how we can route our localhost applications running on our server to a domain that we own(like www.domain.com etc … )
The Why?
Generally, to access applications that are running on our server, we have to be on the same network or there should be another proxy setup infront of our actual server so that, we do not open our server to the internet.
Most common way of doing it might be to setup tailscale both on the clients and server so that they be on the same network. but we have to turn this VPN all the time to access the applications on server.
Instead, we could setup a cloudflare tunnel on the server which routes all of the traffic that reaches the domain that we configure to the server, without needing to open the server to public access.
The How?
There are 5 steps to setup this
installing the Cloudflare daemon
logging in with our Cloudflare account(and also setting up the domain that we wanna use)
creating a tunnel
setting up routes to each service
Editing the configuration file
(Note: Every step has to be done on the server itself and can be done via CLI)
Installing the Cloudflare daemon
Here is the Official Page from where you can download the daemon based on the architecture.
Logging in with Cloudflare
Once the daemon is installed, we have to login with our cloudflare account. This can be done by the command
cloudflared tunnel login
Creating a tunnel
Once we are logged in and setup the domain that we wanna use, we next have to create a tunnel for cloudflare to access the server. To set this up use the command
cloudflared tunnel create <name>
This will create a tunnel( a sample output is shown below)

Creating Routes
For adding any application, we first have to create a route and then point it to the actual locally running route.
For example I created a route called nc.<IP>.xyz where i want to access nextCloud. and so my first command is:
cloudflared tunnel route dns tunnelmain <route>

Once, the tunnel is created, we have to edit the config.yaml file that is located at /etc/cloudflared where we modify the ingress section with all the routes that we configure.

sudo systemctl status retart cloudflared
Once, everything is done successfully, we can access the application that we defined at the route.

