Cloudflare Tunnels VS ngrok
Tags: internet, proxy, webdev, production
Published: 2024-05-18 18:48:22

# TL;DR
Reverse proxy solutions are a great and straightforward method to expose your dev (and possibly production) server to the internet. The two prominent ones are [ngrok](https://ngrok.com/) and [Cloudflare tunnels](https://www.cloudflare.com/products/tunnel/). This article recommends both of them and compares and contrasts them on a high level.

# Introduction
As mentioned in my previous article, [one can monitor their server](https://dev.to/amjadmh73/easily-monitor-your-server-from-anywhere-oma) using one of many solutions, and in order to expose your web or home server without opening a port on your firewall and possibly having to configure a static public IP, you need to use a reverse proxy solution to solve that problem. The two most reliable ones in the market at the time of writing this article are `ngrok` and `Cloudflare Tunnels`.

# ngrok
Ngrok is the one that pops up the most in YouTube videos and online articles since it quite easy to setup and get up and running. The [steps can be found here](https://ngrok.com/docs/guides/getting-started/) which include running a simple web server, installing ngrok, configuring the auth token, and running the reverse proxy agent.

# Cloudflare tunnels
To run the `cloudflared` tunnel agent and have one up and running, you need to follow these steps:
1. Create an account with Cloudflare by [going to their website here](https://www.cloudflare.com/plans/) and choosing the free plan.
2. Fill up the information needed, which are an email address and a password at the time of writing this article.
3. It will then take you to their dashboard where you need to do two things, register, link, or transfer a domain, and then create a tunnel in their Zero Trust dashboard. The screenshots below explain the steps.

**3.1** Cloudflare domain
![Cloudflare active domain](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tkk4qhd488603kp9ij3g.png)

**3.2** Cloudflare dashboard w/ `ZeroTrust` tab
![Cloudflare dashboard w/ zero trust tab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1uetjz190dqxvrqxi9wa.png)

**3.3** Cloudflare tunnel creation steps
**Note:** The `cloudflared` client is easy to install yet its installation steps are different based on your operating system.
![Cloudflare tunnel creation steps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5fnda2a177zond95d9t.png)

**3.4** Cloudflare active tunnel
![Cloudflare active tunnel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eefzazq7k1039r3qexsb.png)

# My biased thoughts on the two solutions
As stated earlier, both solutions are reliable and they work well. 

My preference is to use ngrok for dev servers, homelabs, and staging environments. Also, the nice thing about `ngrok` it is the fact that it offers subdomains and can work instantly. Also, subdomains are available so you don't have to purchase and maintain one if it's not a requirement.

`Cloudflare`, on the other hand, is more useful in production since it has more servers around the world and has more security configurations. But you need a domain name to use it (though easily offered by them).

# Final Note
No matter whether you need to expose a server, use ssh or RDP, or if you have any other use case, those reverse proxy solutions can certainly be of benefit to you. Choose the one that best suits your needs and proceed with it.

Happy building!