Expose Your Local App to the Internet with Cloudflare Tunnel (Windows Version)

Expose Your Local App to the Internet with Cloudflare Tunnel (Windows Version)

Cloudflare Tunnel provides a secure way to expose your locally-hosted applications to the internet without opening ports or configuring complex network settings. This guide will walk you through the process of setting up Cloudflare Tunnel for your app on Windows, using either the CLI tool or Docker.

Prerequisites

  • A Cloudflare account
  • Your application running on localhost
  • Windows 10 or later

Option 1: Using cloudflared CLI

Steps to Expose Your App

  1. Install cloudflared

    • Download the latest Windows executable from the official Cloudflare website.
    • Rename the downloaded file to cloudflared.exe.
    • Move the file to a location in your PATH, e.g., C:\Windows\System32\.
  2. Authenticate cloudflared Open Command Prompt as Administrator and run:

    cloudflared.exe tunnel login
  3. Create a Tunnel

    cloudflared.exe tunnel create my-app-tunnel
  4. Configure Your Tunnel Create a configuration file config.yml in your desired directory:

    url: http://localhost:3000
    tunnel: my-app-tunnel
    credentials-file: C:\path\to\credentials.json
  5. Start the Tunnel

    cloudflared.exe tunnel run my-app-tunnel
  6. Route Traffic to Your Tunnel

    cloudflared.exe tunnel route dns my-app-tunnel myapp.yourdomain.com

Option 2: Using Docker

Steps to Expose Your App

  1. Install Docker Desktop for Windows Download and install from the official Docker website.

  2. Create a Docker network

    docker network create cloudflared
  3. Run cloudflared in Docker

    docker run -d --name cloudflared --network cloudflared cloudflare/cloudflared:latest tunnel --no-autoupdate run --token YOUR_TUNNEL_TOKEN

    Replace YOUR_TUNNEL_TOKEN with the token obtained from your Cloudflare dashboard.

  4. Connect your app to the network When running your app container, add it to the same network:

    docker run -d --name myapp --network cloudflared myapp:latest
  5. Configure Cloudflare DNS In your Cloudflare dashboard, add a CNAME record pointing to your tunnel's address.

Benefits of Using Cloudflare Tunnel

  • Secure exposure without opening ports
  • End-to-end encryption
  • DDoS protection
  • Easy setup and management
  • Flexibility to use CLI or Docker

By following either of these methods, you can safely and easily share your localhost applications with the world, leveraging Cloudflare's robust infrastructure for security and performance on your Windows machine.

Troubleshooting

  • If you encounter "command not found" errors with the CLI method, ensure cloudflared.exe is in your system PATH.
  • For Docker issues, make sure Docker Desktop is running and you have the necessary permissions.
  • If you face connection issues, check your Windows Firewall settings to allow cloudflared or Docker to access the network.

Thank you for reading! I hope you found this post informative and helpful.

If you have any questions or feedback, feel free to reach out to me on Twitter. I always appreciate hearing from readers and am happy to help with any queries.

Stay tuned for more posts, and happy coding!

Also read