How to Install Nextcloud With Docker Compose: AIO or the Community Image Behind a Reverse Proxy
When you host Nextcloud on a Linux server, Docker Compose lets you define the containers and settings in a YAML file so…
When Cloudflare Tunnel returns an intermittent 502 for your website, the cloudflared connector may have failed to reach your local service on that request. Cloudflare Tunnel uses cloudflared to link Cloudflare to a service running on your host or private network, which Cloudflare calls the origin. The failure can come from cloudflared, the origin service itself, or the route between them.
If the error page says “Unable to reach the origin service,” start by checking whether cloudflared could reach the origin when the error happened. Match the failure time against your Tunnel logs. Next, test the origin directly from the host running cloudflared, verify its route, port, and protocol, and check the origin certificate if you use HTTPS. A Tunnel marked Healthy only confirms that cloudflared is connected to Cloudflare. It does not confirm that your origin is responding.
A visitor's request travels through Cloudflare and cloudflared before it reaches your origin. A Tunnel-specific 502 points to a breakdown between cloudflared and the origin. Cloudflare separates this from error 1033, which means Cloudflare cannot find a healthy connector at all. The Tunnel troubleshooting documentation lists common origin connection failures and shows how they appear in logs.
Before you change any settings, record the exact time and time zone of the failure, the requested URL, the error text, and whether that same route works at other times. If you run more than one cloudflared connector, note which connector handled the request. Comparing a failed request against a working one helps you narrow down the cause.
Check the Tunnel status in the dashboard, keeping in mind that it only reflects the link between cloudflared and Cloudflare. If Cloudflare marks the Tunnel Down or Degraded, check that the cloudflared process is running and that its host can reach the network. Even when the Tunnel shows Healthy, the origin can still fail:
Cloudflare covers certificate failures in its guidance on HTTPS origins.
Check the logs around the exact time the 502 occurred. You can view live logs in the Cloudflare dashboard under Networking > Tunnels > your tunnel > Live logs, as long as your account has Tunnel edit permissions. Read-only roles cannot open the log stream. You can also run cloudflared tail <TUNNEL-UUID> from an authenticated machine while the tunnel is active.
Remote log streams stay open for up to one hour and can drop entries during heavy traffic. By default, cloudflared writes log messages to standard error instead of saving them to a file on the server. Because of those limits, capture the connector's output directly on its host as well, especially during brief incidents or traffic spikes. Cloudflare's Tunnel log documentation explains these logging options and their limits.
Look for the log entry that lines up with the failed request:
connect: connection refused error means nothing accepted the connection on that address and port at that moment.cloudflared is using a different protocol than the one the origin expects.x509 error points to certificate validation. The rest of the message tells you whether the certificate name mismatched or cloudflared does not trust the certificate authority.Send a direct request to the origin from the same host and network where cloudflared runs, using the exact service URL from your route. If your route points to http://localhost:8080, run:
curl -v http://localhost:8080
If that request fails from the connector host, troubleshoot the origin service and its local network before you touch Cloudflare settings. If the origin runs in a container, verify that the connector can reach it. You can also check whether a process is listening on the expected port:
# Linux
ss -tlnp | grep 8080
# macOS
lsof -iTCP -sTCP:LISTEN -nP | grep 8080
When cloudflared and the origin run in separate containers, localhost inside the connector container points back to the connector container itself. Test with the network address that the connector can reach from its container. If only some requests fail, run the same test from every connector host. One host might have a different route, listen on a different port, or run a service in a different state.
Visitors request your public hostname, and the Tunnel route's service URL tells cloudflared where to forward those requests. Make sure the public hostname matches the ingress rule you expect, and confirm that the rule's service URL uses a reachable address, the origin's port, and the right protocol. Never point the service URL back to the public hostname that resolves to the Tunnel.
For locally managed tunnels, you can validate the configuration and see which rule matches a URL first:
cloudflared tunnel ingress validate
cloudflared tunnel ingress rule https://foo.example.com
Replace the example URL with your public hostname. A locally managed ingress file must end with a catch-all rule to handle any request that earlier rules do not match, such as returning http_status:404. Cloudflare's configuration file documentation details how these rules and commands work.
A protocol mismatch causes cloudflared to send HTTP traffic to an HTTPS listener or HTTPS traffic to an HTTP listener. Confirm that the service URL uses http:// or https:// to match what the origin listener expects. Your public site's SSL/TLS mode in Cloudflare does not choose or validate the protocol or certificate used between cloudflared and your local origin.
When your service URL uses HTTPS, cloudflared validates the origin's certificate. The connector must trust the certificate, and the certificate's name must match what cloudflared expects. If your service URL uses localhost while the certificate covers app.example.com, set originServerName to app.example.com so cloudflared validates the certificate against that name.
If a private certificate authority issued the certificate, point caPool to that trusted CA or add the CA to the connector host's trust store. Keep certificate verification turned on while you fix the name or trust problem. Cloudflare treats noTLSVerify as a temporary last resort rather than a permanent setting. You can find these certificate options in the HTTPS origin troubleshooting guidance.
Do not raise connection timeouts to work around an intermittent 502. Cloudflare sets connectTimeout to 30 seconds by default when cloudflared opens a new TCP connection to the origin, and TLS setup uses a separate timeout. Fix refused connections, wrong ports, and certificate mismatches directly, since Cloudflare does not recommend changing timeouts as a general fix for 502 errors. See the origin parameter reference for details.
If your logs show DNS lookup errors, QUIC handshake timeouts, or failed connections to Cloudflare, check the connector's DNS and outbound firewall before you investigate your local application. Cloudflare Tunnel sends QUIC traffic over UDP port 7844 and HTTP/2 traffic over TCP port 7844. When a firewall blocks QUIC, cloudflared retries with longer waits each time before it switches to HTTP/2. If the firewall also blocks TCP port 7844, cloudflared cannot fall back.
Cloudflare documents a specific case with Palo Alto Networks firewalls: App-ID database version 9128 or later requires the quic-base App-ID, along with the previously required App-IDs and dependencies, to allow Tunnel QUIC traffic over UDP 7844. That requirement applies to QUIC traffic through that firewall rather than to Tunnel 502 errors in general. You can compare connector-to-Cloudflare network errors with origin connection errors on the Tunnel troubleshooting page.
A Tunnel can run multiple cloudflared replicas on separate hosts or in separate environments. If your logs identify which replica handled a failed request, test whether that specific replica can reach the origin, then compare its route and local service against your other replicas. Running extra replicas increases connector availability, but Cloudflare does not rotate requests across them in order or run health checks against each origin service. Cloudflare explains how this works in its guide to Tunnel availability and failover.
If requests fail across every replica even though direct tests to the origin succeed, save your logs and response details before looking into broader Cloudflare or network issues. General Cloudflare 502 troubleshooting covers other types of 502 errors, so first confirm whether the visitor saw the Tunnel-specific “Unable to reach the origin service” message. If you open a ticket with Cloudflare about a suspected 502 or 504, its support guidance asks you to include the timestamp and time zone, the failing URL, and the output from https://<YOUR_DOMAIN>/cdn-cgi/trace.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com