# Cloudflare Tunnel Quick Start

## Current Status
- ✅ You're logged into Cloudflare via browser
- ✅ Script ready on Nginx proxy: `/tmp/setup-tunnel-non-interactive.sh`
- ✅ Domain: `rpc.d-bis.org` (from .env)
- ⚠️ Need to authenticate cloudflared

## Quick Setup (2 Steps)

### Step 1: Authenticate Cloudflared

SSH to Nginx proxy and run:

```bash
ssh besuadmin@20.160.58.99
sudo cloudflared tunnel login
```

**What happens:**
1. Command displays a URL like: `https://one.dash.cloudflare.com/...`
2. **Open this URL in your browser** (while logged into Cloudflare)
3. Click **"Authorize"** 
4. Authentication completes automatically

### Step 2: Run Automated Setup

After authentication completes, run:

```bash
/tmp/setup-tunnel-non-interactive.sh rpc.d-bis.org
```

**What the script does:**
1. ✅ Creates tunnel: `phase1-nginx-proxy`
2. ✅ Configures tunnel for `rpc.d-bis.org`
3. ✅ Creates DNS record via Cloudflare API (using credentials from .env)
4. ✅ Starts Cloudflared service
5. ✅ Enables service to start on boot

## Verify Setup

After running the script:

```bash
# Check service status
sudo systemctl status cloudflared

# Check tunnel list
sudo cloudflared tunnel list

# Test endpoint
curl https://rpc.d-bis.org/health
```

## Troubleshooting

### Already Authenticated?
If you see "Already authenticated", skip Step 1 and go directly to Step 2.

### DNS Record Already Exists?
The script will update the existing record automatically.

### Service Not Starting?
Check logs:
```bash
sudo journalctl -u cloudflared -f
```

### Verify Configuration
```bash
sudo cat /etc/cloudflared/config.yml
```

## Expected Result

After setup:
- ✅ Tunnel running: `phase1-nginx-proxy`
- ✅ DNS: `rpc.d-bis.org` → `<tunnel-id>.cfargotunnel.com`
- ✅ Service: `cloudflared` running and enabled
- ✅ Endpoint: `https://rpc.d-bis.org/health` returns "healthy"

---

**Ready?** Run the 2 steps above to complete the Cloudflare Tunnel setup!

