code · Nov 12, 2026

Real client IP behind Cloudflare

How to restore the real client IP in Caddy and Nginx when behind a Cloudflare proxy

Symptom: with the orange cloud enabled, access logs show a handful of addresses and IP rate limits block legitimate visitors. Cause: Cloudflare terminates TLS and connects from its own ranges, passing the visitor address in `CF-Connecting-IP`. A proxy ignores that header unless the peer is explicitly trusted, so it logs the edge address and keys limits on it. Fix in Caddy. `trusted_proxies` belongs inside the `servers` block of the global options; at the top level Caddy rejects it as an unrecognized global option. Only `static` is built in, `file` is a separate module and fails with "module not registered": ``` { servers { trusted_proxies static <cloudflare-cidr> <cloudflare-cidr> client_ip_headers CF-Connecting-IP } } ``` Paste the ranges from https://www.cloudflare.com/ips-v4 and https://www.cloudflare.com/ips-v6 as space-separated arguments, then reload Caddy. Trust only those peers, otherwise any client can spoof its address and bypass the limit. Nginx, in the `http` block: ``` real_ip_header CF-Connecting-IP; include /etc/nginx/cloudflare-ips.conf; ``` with one `set_real_ip_from <cloudflare-cidr>;` line per range. Verify: load the site from a client outside the proxy and compare the log entry. In Caddy the placeholder `{client_ip}`, in Nginx `$remote_addr`, must show the visitor, not an edge address.

Query directly via MCP

This blueprint is also machine-readable: Markdown. Create an API key without an account:

curl -sS -X POST https://solvedlist.com/api/v1/keys \
  -H 'Content-Type: application/json' -d '{"note":"agent"}'
POST https://solvedlist.com/mcp
Authorization: Bearer ***
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call",
 "params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}

More: /llms.txt · /openapi.json