Documentation Index
Fetch the complete documentation index at: https://docs.americ.io.vn/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Ubuntu/Debian VPS with a web app running (e.g. on
localhost:8080) - A domain already on Cloudflare (nameservers pointing to Cloudflare)
- A Cloudflare account with Zero Trust enabled (free tier is sufficient)
- A Google Cloud account (for OAuth credentials)
Phase 1 — Install cloudflared on the VPS
1.1 Download and install
1.2 Authenticate with Cloudflare
~/.cloudflared/cert.pem.
1.3 Create the tunnel
Save the UUID — you will need it in the next phase.
Phase 2 — Configure and run the tunnel
2.1 Write config.yml
Create the file at~/.cloudflared/config.yml:
<YOUR_TUNNEL_UUID> with the UUID from Phase 1, and app.yourdomain.com with your actual subdomain.
2.2 Create the DNS record
2.3 Run as a systemd service
Phase 3 — Create an Access Application
In the Cloudflare Zero Trust dashboard:- Go to Access → Applications → Add an application
- Select Self-hosted
- Set Application domain to
app.yourdomain.com - Under Policies, click Add a policy:
- Policy name: e.g.
Allowed users - Action:
Allow - Rule selector:
Emails - Value: add each allowed address, e.g.
alice@gmail.com,bob@gmail.com
- Policy name: e.g.
- Save the application
Anyone not in the email list will be blocked at the Cloudflare edge — your VPS never receives their request.
Phase 4 — Add Google as Identity Provider
4.1 Create OAuth credentials in Google Cloud
- Go to Google Cloud Console → APIs & Services → Credentials
- Click Create Credentials → OAuth 2.0 Client ID
- Application type: Web application
- Under Authorized redirect URIs, add:
Replace
<your-team-name>with your Cloudflare Zero Trust team name (found in Zero Trust → Settings → General). - Save — copy the Client ID and Client Secret
4.2 Add Google IdP in Cloudflare Zero Trust
- Go to Settings → Authentication → Login methods
- Click Add → Google
- Paste your Client ID and Client Secret
- Click Save
- Optionally click Test to confirm the connection works
How it works end-to-end
8080 is never exposed to the public internet. All traffic flows through the encrypted tunnel.
Customizing the Access login page
Cloudflare allows limited branding on the login page:- Logo — upload a custom image
- App name — shown as the page title
- Background color — a single hex value
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
cloudflared not found after install | PATH not updated | Run source ~/.bashrc or open a new shell |
| Tunnel auth URL doesn’t work | VPS has no browser | Copy the URL and open it on your local machine |
| 502 Bad Gateway | App not running on the configured port | Check your service is up: curl localhost:8080 |
| Google login succeeds but access denied | Email not in policy | Add the email in Zero Trust → Access → your app → policy |
| Tunnel not running after reboot | Service not enabled | Run sudo systemctl enable cloudflared |