Tunnel Run Configuration, Log Streams, Prometheus Metrics and Authentication Errors
How to configure cloudflared tunnels, collect logs and metrics, fix credential errors, and understand locally- versus remotely-managed setups.
This page summarises Cloudflare Tunnel documentation for operators who run the cloudflared connector: wiring up config.yml, choosing run flags, reading logs, scraping Prometheus metrics, and fixing the most common startup and authentication failures.
Locally-managed tunnel versus remotely-managed tunnel
Section titled “Locally-managed tunnel versus remotely-managed tunnel”Cloudflare recommends a remotely-managed tunnel for most production setups because configuration lives on Cloudflare and you can manage it from the dashboard, API, or Terraform.
Cloudflare recommends creating a remotely-managed tunnel for most use cases. Remotely-managed tunnels store their configuration on Cloudflare, which allows you to manage the tunnel from any machine using the dashboard, API, or Terraform.
— Cloudflare, Locally-managed tunnels
A locally-managed tunnel is created with cloudflared tunnel create <NAME> on the command line; settings and credential files sit in your local cloudflared directory. That model suits local development, testing, or legacy layouts.
| Aspect | Remotely-managed | Locally-managed |
|---|---|---|
| Configuration storage | Cloudflare | Local ~/.cloudflared (or OS-specific paths) |
| Minimum to run | Tunnel token (--token or TUNNEL_TOKEN) |
tunnel UUID + credentials-file in config.yml |
| Who can run it | Anyone with the token | Holder of the tunnel JSON credentials (and account cert for management) |
For remotely-managed tunnels, anyone who possesses the token can run the connector—treat tokens like secrets and rotate them if compromised. See Tunnel tokens and Tunnel permissions.
config.yml: path, required fields and when you need it
Section titled “config.yml: path, required fields and when you need it”Quick Tunnels do not need a configuration file. For locally-managed tunnels you edit YAML (often $HOME/.cloudflared/config.yml on Linux) or pass flags on the CLI for a single service.
The CLI provides a quick way to handle configurations if you are connecting a single service through cloudflared. The tunnel configuration file is useful if you are connecting multiple services and need to configure properties or exceptions for specific origins.
— Cloudflare, Configuration file
Default search paths for credentials and config are listed in Useful terms: Windows uses %USERPROFILE%\.cloudflared; macOS and Unix-like systems try ~/.cloudflared, then /etc/cloudflared, then /usr/local/etc/cloudflared.
Minimum fields to run as a system service (local management)
Section titled “Minimum fields to run as a system service (local management)”On Linux, macOS, and Windows services, Cloudflare expects at least:
| Argument | Role |
|---|---|
tunnel |
Tunnel UUID |
credentials-file |
Path to <TUNNEL-UUID>.json from cloudflared tunnel create |
Example shape from Create a locally-managed tunnel:
url: http://localhost:8000tunnel: <Tunnel-UUID>credentials-file: /home/you/.cloudflared/<Tunnel-UUID>.jsonUse your real home directory—not a copied /root/ path. Override the config path with --config (default ~/.cloudflared/config.yml); see Run parameters — config.
cloudflared tunnel run parameters: CLI flags versus service
Section titled “cloudflared tunnel run parameters: CLI flags versus service”Run parameters apply to cloudflared tunnel run. For remotely-managed tunnels, add flags to the OS service definition; for locally-managed tunnels, use the same keys in YAML. The authoritative list is Run parameters and the shorter Configuration — Run parameters overview.
Commonly used run flags
Section titled “Commonly used run flags”| Parameter | Default | Purpose |
|---|---|---|
--loglevel |
info |
Verbosity: debug, info, warn, error, fatal |
--logfile |
stdout |
Write logs to a file (no rotation by cloudflared) |
--log-directory |
— | cloudflared.log with 1 MB rotation, up to five backups |
--output |
default |
json per-line logs (needs cloudflared 2025.6.1+) |
--metrics |
See metrics section | Prometheus scrape address |
--protocol |
auto |
auto, quic, http2 |
--region |
global | Only us routes through US data centers |
--token |
— | Remotely-managed tunnel association |
Example from Configuration:
cloudflared tunnel --loglevel info --logfile /var/log/cloudflared/cloudflared.log run --token <TOKEN VALUE>On Linux, edit cloudflared.service with sudo systemctl edit --full cloudflared.service, adjust ExecStart, then sudo systemctl restart cloudflared. macOS uses com.cloudflare.cloudflared launchd ProgramArguments; Windows uses the cloudflared service ImagePath in the registry. Full steps are in Add run parameters to tunnel service.
Logging flags: logfile versus log-directory
Section titled “Logging flags: logfile versus log-directory”Use the
--logfileflag instead for short troubleshooting sessions or when another tool manages rotation. cloudflared does not rotate the file specified by--logfile. If you set both flags,--logfiletakes precedence.— Cloudflare, Log streams
At debug, cloudflared may log URLs, methods, and headers—useful for diagnosis, risky for sensitive data (Run parameters — loglevel).
Tunnel logs: server files, JSON output and cloudflared tail
Section titled “Tunnel logs: server files, JSON output and cloudflared tail”Tunnel logs record activity between cloudflared and the Cloudflare network and between cloudflared and your origin (Observability — Logs).
On the origin server
Section titled “On the origin server”By default logs go to stderr and are not persisted. For JSON (Kubernetes or log pipelines):
cloudflared tunnel --output json run <UUID>For rotated files:
cloudflared tunnel --loglevel info --log-directory <PATH> run <UUID>In Kubernetes, fetch pod output with kubectl logs as shown in the Kubernetes deployment guide.
Remote live stream with cloudflared tail
Section titled “Remote live stream with cloudflared tail”From a machine where you ran cloudflared tunnel login, stream logs for a tunnel UUID:
cloudflared tail <UUID>Filter with --event (cloudflared, http, tcp, udp), --level, or --sampling (0.0–1.0) to reduce load on busy origins. Pipe JSON through jq when using cloudflared tail --output=json <UUID> | jq ..
Prometheus tunnel metrics: default bind address and --metrics
Section titled “Prometheus tunnel metrics: default bind address and --metrics”When a tunnel runs, cloudflared exposes a Prometheus HTTP endpoint.
Tunnel metrics show a Cloudflare Tunnel’s throughput and resource usage over time. When you run a tunnel, cloudflared will spin up a Prometheus metrics endpoint — an HTTP server that exposes metrics in Prometheus format.
— Cloudflare, Tunnel metrics
| Environment | Default bind |
|---|---|
| Non-containerized | 127.0.0.1:<PORT>/metrics, port first free in 20241–20245 |
| Docker / Kubernetes | 0.0.0.0:<PORT>/metrics |
Find the port in startup logs, e.g. Starting metrics server on 127.0.0.1:20241/metrics. Custom address:
cloudflared tunnel --metrics 127.0.0.1:60123 run my-tunnelUse the host’s LAN IP instead of 127.0.0.1 when Prometheus runs on another machine; use 0.0.0.0 to listen on all interfaces (Configure the metrics server address).
You cannot push metrics directly from cloudflared to Grafana. Prometheus scrapes /metrics; Grafana reads Prometheus (Monitor Cloudflare Tunnel with Grafana). Useful series include cloudflared_tunnel_total_requests, cloudflared_tunnel_request_errors, QUIC RTT gauges, and HA connection counters—see the metric tables on Metrics and Observability.
Tunnel permissions: cert.pem, credentials JSON and tunnel token
Section titled “Tunnel permissions: cert.pem, credentials JSON and tunnel token”Two local files govern locally-managed tunnels (Tunnel permissions):
Account certificate cert.pem |
Tunnel credential <UUID>.json |
|
|---|---|---|
| Issued by | cloudflared tunnel login |
cloudflared tunnel create <NAME> |
| Scope | Account-wide tunnel management | Run one tunnel only |
| Needed to | Create, delete, route, list tunnels | Run tunnel; reference in config.yml |
Remotely-managed tunnels need only the tunnel token (Tunnel tokens). Revoke a compromised account cert by deleting the Cloudflare Tunnel API token in the dashboard, then run cloudflared tunnel login again.
cloudflared tunnel login and authentication failures
Section titled “cloudflared tunnel login and authentication failures”Login opens a browser, you pick a hostname, and cert.pem is written to the default directory (Create a locally-managed tunnel).
When user permissions change (if that user is removed from the account or becomes an admin of another account, for example), Cloudflare rolls the user’s API key. However, the certificate file downloaded through cloudflared retains the older API key and can cause authentication failures. The user will need to login once more through cloudflared to regenerate the certificate.
— Cloudflare, Common errors
Alternatively, use a dedicated service account for cloudflared login. Specify a non-default account cert with --origincert (default ~/.cloudflared/cert.pem) on locally-managed runs (Run parameters — origincert).
Common tunnel errors and quick fixes
Section titled “Common tunnel errors and quick fixes”Tunnel credentials file missing or not a file
Section titled “Tunnel credentials file missing or not a file”If you encounter the following error when running a tunnel, double check your config.yml file and ensure that the credentials-file points to the correct location. You may need to change /root/ to your home directory.
— Cloudflare, Troubleshooting
Typical log line: Tunnel credentials file '...json' doesn't exist or is not a file. Fix the credentials-file path and confirm the JSON exists after cloudflared tunnel create.
Stale connections after unclean shutdown
Section titled “Stale connections after unclean shutdown”Use cloudflared tunnel cleanup <NAME or UUID> or cloudflared tunnel cleanup --connector-id <CONNECTOR-ID> <NAME or UUID> before delete/run retries (Useful commands).
Compromised remotely-managed token
Section titled “Compromised remotely-managed token”Refresh the token in the dashboard or API, DELETE tunnel connections via the documented API, reinstall the service with the new token on each replica, and verify with systemctl status cloudflared.
Common mistakes
Section titled “Common mistakes”- Pointing
credentials-fileat another user’s home directory (especially when copying sampleconfig.yml). - Running locally-managed tunnels without
tunnelandcredentials-filein the service config (Linux as a service). - Expecting Grafana to scrape
cloudflareddirectly instead of Prometheus. - Binding metrics only to
127.0.0.1while Prometheus runs on a different host. - Using
debugloglevel in production without log redaction.
How to check this on your site
Section titled “How to check this on your site”- Confirm the tunnel process is up: on Linux run
sudo systemctl status cloudflaredafter service changes (Run parameters); in Kubernetes usekubectl logson thecloudflaredpod (Kubernetes guide). - Validate local config paths:
credentials-fileand optionalconfigpath match files under your default cloudflared directory. - Open the metrics URL from startup logs or your
--metricssetting and confirm Prometheus can scrapecloudflared_tunnel_total_requests(Grafana tutorial). - For live debugging without SSH, authenticate locally and run
cloudflared tail <UUID>with--levelfilters as needed (Log streams). - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match your setup or the linked Cloudflare documentation, email yimasynthetic@gmail.com with the page URL and the exact statement you are questioning so it can be corrected or clarified.