Skip to content
Go back

Expose Your Localhost app to the Internet with Custom domain using Cloudflare Tunnel

Published:

Since you can’t use a custom domain with the free ngrok plan, but your domain is hosted on Cloudflare, here’s a fully free, reliable alternative:


✅ Use Cloudflare Tunnel (Argo Tunnel) — 100% FREE, allows custom domains

You’ll expose your local site (like your localhost site) directly through your own domain using cloudflared, without needing ngrok at all.


🌐 Goal:

You want to expose your local app (e.g. running on http://localhost:3000) to:

https://your-subdomain.yourdomain.com

e.g.

https://local.janakkumarshrestha0.com.np

✅ Step-by-Step: Use Cloudflare Tunnel with Custom Domain

1. Make sure your domain is on Cloudflare


2. Install cloudflared on your machine

For Debian/Ubuntu-based systems:

wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb

Other OS? See: https://developers.cloudflare.com/cloudflared/install/


3. Authenticate cloudflared with Cloudflare

Run:

cloudflared tunnel login

This opens a browser. Log in to your Cloudflare account and authorize.


4. Create a tunnel

cloudflared tunnel create mytunnel

This will generate a credentials-file and tunnel ID inside /home/YOUR_USERNAME/.cloudflared/.


5. Create a config file

Create the file:

sudo mkdir -p /etc/cloudflared
sudo nano /etc/cloudflared/config.yml

Paste this, replacing the values:

tunnel: YOUR_TUNNEL_ID
credentials-file: /home/YOUR_USERNAME/.cloudflared/YOUR_TUNNEL_ID.json

ingress:
  - hostname: local.janakkumarshrestha0.com.np
    service: http://localhost:3000
  - service: http_status:404

Replace:


6. Route DNS through the tunnel

cloudflared tunnel route dns mytunnel local.janakkumarshrestha0.com.np

Cloudflare will automatically add the correct DNS record (CNAME).


7. Start the tunnel

cloudflared tunnel run mytunnel

✅ DONE! Your local site is now live at:

https://local.janakkumarshrestha0.com.np

🔁 Optional: Auto-start the tunnel at boot

You can enable the tunnel as a system service:

sudo cloudflared service install

🔒 Bonus: Secure with Access Rules (Optional)

You can protect your tunnel with Cloudflare Access (Google login, OTP, etc.) — all free.



Suggest Changes

Previous Post
Make your localhost app live on the internet using ngrok.
Next Post
Linux-M3 - Introduction to Shell Scripting