> ## Content Index
> Fetch the complete content index at: https://blogs.gardazi.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# My Server Was Fine. The Road to It Wasn't.
- URL: https://blogs.gardazi.com/my-server-was-fine-the-road-to-it-wasnt/
- Published: 2026-11-24T11:38:44.000Z
- Updated: 2026-11-24T11:38:44.000Z
- Description: Overleaf started throwing Cloudflare 522s while the server sat idle. The real problem was a carrier link between Singapore and Europe. Here's how I found it and why I ended up putting everything behind a Cloudflare Tunnel.
- Author: Syed Talha Ahmed Gardazi
- Tags: Self-Hosting, Networking, Cloudflare

Last night I opened my self-hosted Overleaf at ol.gardazi.com and got Cloudflare's 522 page. Connection timed out. The page helpfully tells you the most likely cause is "something on your server is hogging resources". So that's where I looked first.

## The server was bored

It's an Oracle Cloud ARM box in Singapore, managed with Coolify. Load average around 1.1 on 4 cores. 18 GB of RAM free. Overleaf, Mongo and Redis had been up for six days, and the logs were just cron jobs doing cron things.

Hitting Overleaf from inside the server took 7 ms. Through Caddy, the reverse proxy Coolify puts in front of everything, 12 ms. Nothing wrong there.

## Skipping Cloudflare

Next test was from my laptop in Vienna. Once straight to the server's IP, once through Cloudflare like a normal visitor.

![curl results direct vs through Cloudflare](https://blogs.gardazi.com/content/images/2026/11/cf-tunnel-01-curl.png)

Direct: eight out of eight. Through Cloudflare: about half of them die.

Direct was 8 out of 8, every time. Through Cloudflare roughly half timed out. My Homepage dashboard on the same box failed 3 out of 3 as well, so this wasn't an Overleaf problem. Something between Cloudflare and the server was eating connections.

## Watching the handshake

The server didn't even have tcpdump installed, which tells you how often I debug networking on it. After installing it I captured only SYN and RST packets on port 443 while sending requests through Cloudflare.

![tcpdump showing repeated SYN-ACK retransmits](https://blogs.gardazi.com/content/images/2026/11/cf-tunnel-02-tcpdump.png)

Cloudflare's SYN arrives. The server answers. The answer never makes it back.

Cloudflare's SYN reaches the server fine. The server replies with a SYN-ACK. A second later it sends the SYN-ACK again, then again two seconds after that. That's the kernel retransmitting because the final ACK never came. Either the SYN-ACK gets lost on its way out, or Cloudflare's ACK gets lost on its way in. The server is doing its job. The network isn't.

The other thing worth noticing is 104.23.122.80\. It was 163 ms away from the server, so it isn't Cloudflare Singapore, which is about 1 ms from Oracle's data centre there. Since I'm in Vienna, my requests land on Cloudflare's Vienna location, and Vienna is what opens the connection to my origin. Halfway around the planet, over the public internet.

## Following the route

mtr in TCP mode toward that Cloudflare address showed where it fell apart.

![mtr showing packet loss on Arelion hops](https://blogs.gardazi.com/content/images/2026/11/cf-tunnel-03-mtr.png)

Hop 7 drops 87% of packets. After that, silence.

Hop 6 is already shaky, averaging 432 ms with spikes past 2 seconds. Hop 7 loses 87% of packets and nothing after it answers at all. All of those addresses are in 62.115.0.0/16, which is Arelion, the carrier formerly known as Telia. So Oracle's upstream was sending my replies to Europe through an Arelion link having a very bad day.

Cloudflare's status page was clean. From their side nothing was broken.

## "But I didn't change anything"

Correct. Neither did anyone I could complain to. Carriers move traffic around constantly: congestion, maintenance, a cable fault somewhere, a routing change. Last week the replies from my server probably took a different path, or this link was healthy. Traffic is also spread over several parallel links, which is why it failed half the time instead of every time.

A few hours later it fixed itself. Nice, but it also means the same thing can happen again at some random moment, and there's nothing on my server I could have done to prevent it.

## Side quest: is the box just slow?

Something had bugged me for a while. SSH into this server always felt sluggish compared to my other Oracle box in Frankfurt. Same shape, same 4 ARM cores. So I ran the same checks on both.

![singapore vs germany server benchmark](https://blogs.gardazi.com/content/images/2026/11/cf-tunnel-05-slow.png)

Same machine, basically. Different distance.

Identical, and Singapore even wins a couple. The only number that differs is the last one. Every keystroke travels to Singapore and back before it shows up on screen, and 170 ms is very noticeable when you're typing. The machine isn't slow, the speed of light is. mosh hides it nicely if it bothers you.

## What I could do about it

- Wait. Free, and it'll happen again.
- Turn off Cloudflare's proxy for the affected records. Instant, but the server IP is out in the open and nothing sits in front of it.
- Pay for Argo Smart Routing so Cloudflare carries the traffic on its own backbone. Works, costs money every month.
- Move everything to the Frankfurt box. Closer to me, but a real migration.
- Run a Cloudflare Tunnel on the server.

I went with the tunnel.

## What a tunnel changes

A small daemon called cloudflared runs on the server and opens outbound connections to Cloudflare. Mine connects to the Singapore locations, 1 ms away. When a request hits Cloudflare in Vienna, Cloudflare carries it over its own network to Singapore and down that already open connection. The broken public route between Oracle and Europe just isn't part of the trip anymore. That's the diagram at the top of this post.

A couple of bonuses come with it. Nothing has to connect into the server, so ports 80 and 443 can be closed later, and the origin IP stops mattering.

## Making it play nice with Coolify

Coolify runs Caddy in front of every app and Caddy routes by hostname. I didn't want to touch a single app. The usual advice is to point the tunnel at Caddy on port 80 and change every app's domain from https:// to http:// in Coolify, otherwise Caddy keeps redirecting to HTTPS forever. There are around twenty apps on this box and I wasn't going to redeploy all of them.

Instead the tunnel points at Caddy's HTTPS port, with two extra settings:

```
ingress:
  - hostname: "*.gardazi.com"
    service: https://coolify-proxy:443
    originRequest:
      noTLSVerify: true
      matchSNItoHost: true
  - service: http_status:404
```

`matchSNItoHost` makes cloudflared send the real hostname in the TLS handshake, so Caddy picks the right certificate and the right app. `noTLSVerify` means cloudflared won't care when that certificate eventually expires, which it will once Let's Encrypt can't reach port 80 anymore. Visitors never see Caddy's certificate anyway, they see Cloudflare's. Net result: nothing changes in Coolify.

## Doing it without breaking things

1. **A scoped API token.** Cloudflare Tunnel edit, DNS edit, Zone read, expiring in 30 days. Not the global key.
2. **Back up every DNS zone** through the API, as JSON and as a BIND export. If anything goes sideways, it all goes back.
3. **Create the tunnel through the API** with the config stored on Cloudflare's side, with routes for gardazi.com, the wildcard, and the other domains living on the same box.
4. **Run cloudflared** as a small compose project on Coolify's Docker network. Two replicas, so one crashing doesn't take every site down.

```
x-cf: &cf
  image: cloudflare/cloudflared:2025.11.1
  command: tunnel --no-autoupdate --metrics 0.0.0.0:2000 run
  env_file: .env          # TUNNEL_TOKEN=...
  restart: unless-stopped
  networks: [coolify]
services:
  cloudflared-1: *cf
  cloudflared-2: *cf
networks:
  coolify:
    external: true
```

1. **Test Caddy from the tunnel's network first,** before touching DNS, with a throwaway curl container on the coolify network and `--resolve`.
2. **Move one hostname.** I already had a wildcard A record for \*.gardazi.com, so an explicit CNAME for ol.gardazi.com pointing at `<tunnel-id>.cfargotunnel.com` overrides the wildcard for just that name. Everything else stays on the old path.

![cloudflared connecting to Singapore and successful requests](https://blogs.gardazi.com/content/images/2026/11/cf-tunnel-04-tunnel-up.png)

Four connections, all in Singapore. Then eight 200s in a row.

Eight for eight, most around 300 ms from Vienna. Overleaf's live editing works too, tunnels handle websockets without any extra config.

## Stuff I'm keeping in mind

- cloudflared is now a single point of failure for every site on the box. Two replicas make that less scary, not gone.
- Cloudflare's free plan limits still apply: 100 MB per upload, 100 second timeout. Same as before the tunnel, still worth remembering.
- Apps get the visitor's IP from the `CF-Connecting-IP` header, not from the connection itself.
- A tunnel only serves domains in the same Cloudflare account. One of mine lives somewhere else and stays on the old setup for now.
- Cloudflare's terms aren't friendly to pushing lots of video through the proxy. Jellyfin stays on Tailscale.

## What's next

The rest of the hostnames move over once Overleaf has run through the tunnel for a few days without surprises. After that, ports 80 and 443 get closed. Until then, rolling back is deleting one DNS record.

The lesson I keep relearning: when a 522 says your server is struggling, check if your server is actually struggling. Mine was asleep. The internet in between wasn't.