Cloudflare tunnels for exposing local servers to the internet
There comes a time when you would want to expose your local server to the internet but you might not want to deploy your local server to a remote server because it’s not ready yet or you might not want to deploy it at all.
For instance, you might want to expose your local WordPress installation to the internet so that you can show it to your client or you might want to expose your local API server to the internet so that you can test it on your mobile device.
In such cases, you can use Cloudflare tunnels to expose your local server to the internet.
To use Cloudflare tunnels, you need to install the Cloudflare Tunnel client called “cloudflared” first.
If you’re on Linux or macOS, you can install it using Homebrew like so.
brew install cloudflared
Or, if you’re on Windows, follow these instructions to install it.
Once installed, you can create a tunnel for your local servers. For instance, I use it to expose my local Jekyll server to the internet like so.
cloudflared tunnel --url http://localhost:4000
As you can tell, I’m exposing my local Jekyll server which is running on port
4000 to the internet.
This will create a tunnel and will give you a URL that you can use to access your local server from the internet that looks something like this.
And that’s it! You can now access your local server from the internet using the URL provided by Cloudflare Tunnels.
Now, this is a quick and dirty way to expose your local server to the internet. But as mentioned in the screenshot above, these account-less Tunnels have no uptime guarantee. If you intend to use Tunnels in production you should use a pre-created named tunnel by following: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps
👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!