Securely exposing your local development server to the internet is a common need, especially for webhooks, remote testing, or temporary demos. Tools like Ngrok are popular but come with limitations on free tiers and may not suit privacy-conscious developers.
In this guide, we’ll show you how to build your own Ngrok-like tunneling system using Cloudflare Tunnels (Argo Tunnel) and NGINX — completely free, fast, and production-ready.
🧰 Requirements
- A domain name managed in Cloudflare DNS
- Ubuntu/Linux server (for tunneling agent)
- Local app running on localhost:3000 (example)
- NGINX installed
- Cloudflare Tunnel client (cloudflared)
Step 1: Add Your Domain to Cloudflare
- Sign in to Cloudflare
- Add your domain.
- Set your nameservers to those provided by Cloudflare.
- Wait for propagation to complete.
Step 2: Install cloudflared
Step 3: Create a Tunnel
cloudflared tunnel login
- This will open a browser and ask for Cloudflare login.
- Choose the domain you want to use.
Then:
cloudflared tunnel create my-tunnel
This generates credentials at ~/.cloudflared
and creates a tunnel ID.
Step 4: Configure the Tunnel Routing
Create a config file:
sudo nano /etc/cloudflared/config.yml
tunnel: <TUNNEL_ID>
credentials-file: /root/.cloudflared/<TUNNEL_ID>.json
ingress:
- hostname: test.yourdomain.com
service: http://localhost:3000
- service: http_status:404
Replace <TUNNEL_ID> and domain accordingly.
Step 5: Run the Tunnel
cloudflared tunnel run my-tunnel
Test your URL: https://test.yourdomain.com
Optional: Run as a Service
Create service file:
sudo systemctl daemon-reexec
sudo systemctl enable --now cloudflared
Step 6: Use NGINX for Local Reverse Proxy (Optional)
If your app needs specific routes or SSL:
Restart nginx: sudo systemctl restart nginx
Use Cases
- Webhooks from Stripe, GitHub, etc.
- Remote demos for clients
- Local API testing from the cloud
📂 Project Structure Summary
/var/www/your-app └── NGINX → localhost:5000 cloudflared → tunnel to test.yourdomain.com
Hope you find this helpful!!
Build Your Own Ngrok Alternative Using Cloudflare Tunnels and NGINX