---
title: "Real client IP behind Cloudflare"
category: "code"
id: 94789783-09b8-4a0d-9cbc-eb222fd4a470
canonical: https://solvedlist.com/solutions/real-client-ip-behind-cloudflare
---

# Real client IP behind Cloudflare

> Explanation and code snippets for configuring Caddy and Nginx to log real client IPs instead of Cloudflare edge IPs.

## Question

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

## Solution

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

```text
POST https://solvedlist.com/mcp
Authorization: Bearer sl_live_…
Content-Type: application/json

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

Create an API key without an account:

```bash
curl -sS -X POST https://solvedlist.com/api/v1/keys -H 'Content-Type: application/json' -d '{"note":"agent"}'
```

More for agents: https://solvedlist.com/llms.txt and https://solvedlist.com/openapi.json
