Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

HTTP Request Headers for Visitor IP, Geolocation and Origin Logging

How reverse-proxy HTTP headers carry the real visitor IP to your origin, which header to trust, and how to log and verify them.

This page summarises Cloudflare documentation on the HTTP headers Cloudflare adds when it proxies traffic to your origin. After you enable the proxy, your server logs usually show Cloudflare edge addresses—not the visitor’s—unless you read the right headers or configure your web server accordingly.

Why the origin sees proxy addresses instead of the visitor IP

Section titled “Why the origin sees proxy addresses instead of the visitor IP”

When traffic is routed through the Cloudflare network, Cloudflare acts as a reverse proxy. Packets reach your origin from Cloudflare IP ranges, so applications that depend on the connection source IP for authentication, rate limiting, or geolocation need extra configuration.

Your origin server sees Cloudflare IP addresses as the source of all requests instead of the end-user’s IP address. Applications that rely on the source IP for authentication, rate limiting, or geolocation will not function as expected without additional configuration.

— Cloudflare, DNS proxy status use cases

Cloudflare documents the original visitor address in request headers such as CF-Connecting-IP and X-Forwarded-For. For logging and app logic, Cloudflare recommends Preferring CF-Connecting-IP or True-Client-IP over parsing X-Forwarded-For.

Visitor IP headers: which one to use at the origin

Section titled “Visitor IP headers: which one to use at the origin”

Cloudflare passes through client request headers and adds its own. The headers below are the ones operators most often ask about when fixing logs, firewall rules, or geolocation.

CF-Connecting-IP: single client address on edge-to-origin requests

Section titled “CF-Connecting-IP: single client address on edge-to-origin requests”

CF-Connecting-IP carries the client IP that connected to Cloudflare. It is sent only on traffic from Cloudflare’s edge to your origin.

CF-Connecting-IP provides the client IP address connecting to Cloudflare to the origin web server. This header will only be sent on the traffic from Cloudflare’s edge to your origin web server.

— Cloudflare, Cloudflare HTTP headers

If this header never appears at the origin, check Transform Rules and Managed Transforms—a rule may be stripping or altering it. See Restoring original visitor IPs for server-specific setup.

X-Forwarded-For: proxy chain versus one reliable IP

Section titled “X-Forwarded-For: proxy chain versus one reliable IP”

X-Forwarded-For lists the original visitor and intermediate proxies. If the incoming request had no X-Forwarded-For, Cloudflare sets it to the same value as CF-Connecting-IP. If one already existed, Cloudflare appends the IP of the proxy that connected to Cloudflare.

To restore the original visitor IP address at your origin web server, Cloudflare recommends that your logs or applications look at CF-Connecting-IP or True-Client-IP instead of X-Forwarded-For. CF-Connecting-IP and True-Client-IP both have a consistent format containing only one IP address.

— Cloudflare, Cloudflare HTTP headers

True-Client-IP: Enterprise legacy header name

Section titled “True-Client-IP: Enterprise legacy header name”

True-Client-IP (Enterprise) holds the same client IP as CF-Connecting-IP; only the header name differs. Some Enterprise deployments keep True-Client-IP so legacy load balancers and firewalls do not need to learn a new name. Enable it via the Add “True-Client-IP” header Managed Transform.

When Pseudo IPv4 is set to Add Header, Cloudflare adds CF-Pseudo-IPv4 with a Class E IPv4 address derived from the visitor’s IPv6 address. When set to Overwrite Headers, Cloudflare overwrites existing CF-Connecting-IP and X-Forwarded-For with that pseudo IPv4 while keeping the real IPv6 in CF-Connecting-IPv6. See Restoring original visitor IPs.

Header Typical use Format at origin
CF-Connecting-IP Default choice for logs and apps Single IP
True-Client-IP Enterprise; legacy devices Single IP (same value as CF-Connecting-IP)
X-Forwarded-For Apps expecting a forwarded chain Comma-separated list; chain grows with extra proxies
CF-Pseudo-IPv4 IPv6 visitors, systems needing IPv4-shaped value Pseudo IPv4 when enabled

Managed Transforms: geolocation headers and hiding visitor IPs

Section titled “Managed Transforms: geolocation headers and hiding visitor IPs”

Managed Transforms let you add or remove visitor-related headers without custom Workers code.

Add visitor location headers: city, country, coordinates

Section titled “Add visitor location headers: city, country, coordinates”

The Add visitor location headers transform adds geolocation fields derived from the visitor IP, including cf-ipcity, cf-ipcountry, cf-ipcontinent, cf-iplongitude, cf-iplatitude, cf-region, cf-region-code, cf-metro-code, cf-postal-code, and cf-timezone. Non-ASCII values are converted to UTF-8 in header values.

Enabling only IP Geolocation in the dashboard (Network → IP Geolocation) adds CF-IPCountry on requests to the origin—even if Add visitor location headers is off.

In order to use this data, you will need to then retrieve it from the CF-IPCountry header.

— Cloudflare, IP geolocation

For the full header list and field mapping, see Available Managed Transforms.

Remove visitor IP headers: privacy and stacked CDN behaviour

Section titled “Remove visitor IP headers: privacy and stacked CDN behaviour”

Remove visitor IP headers strips visitor IP information from headers sent to the origin, including CF-Connecting-IP and True-Client-IP, when you do not want IP data on the origin.

For x-forwarded-for specifically, removal of the leftmost visitor IP happens only when Cloudflare received the request after at least one other CDN. Cloudflare then keeps only the last proxy IP before Cloudflare—for example, after two prior CDNs, the origin might see only the second CDN’s address in x-forwarded-for. Details are in Visitor IP address in the x-forwarded-for HTTP header.

Connection and protocol headers operators rely on

Section titled “Connection and protocol headers operators rely on”

X-Forwarded-Proto: HTTP versus HTTPS as the visitor used

Section titled “X-Forwarded-Proto: HTTP versus HTTPS as the visitor used”

X-Forwarded-Proto reflects whether the visitor used http or https to reach Cloudflare. Cloudflare overwrites a client-supplied value that does not match the actual connection mode.

CF-Visitor is a JSON object with a scheme key (http or https). It matters mainly when you use Flexible SSL in Cloudflare settings.

Cf-Ray (Ray ID): correlate origin logs with Cloudflare support

Section titled “Cf-Ray (Ray ID): correlate origin logs with Cloudflare support”

Cf-Ray encodes the data center and request; as a response header, the trailing three-letter code shows which data center handled the request. The same value is sent toward the origin (and may change when Argo Smart Routing or Argo Tiered Caching reroutes). Logging it at the origin helps match your logs to Cloudflare’s.

The CF-RAY header traces a website request through Cloudflare’s network. Provide the CF-RAY of a web request to Cloudflare support when troubleshooting an issue.

— Cloudflare, Gathering information for troubleshooting sites

If a connection times out with no Cf-Ray in the response, the request likely never reached Cloudflare—sometimes pointing to ISP blocking of Cloudflare IPs. See the same troubleshooting guide.

Restoring the visitor IP in server logs and applications

Section titled “Restoring the visitor IP in server logs and applications”

Documented approach: trust Cloudflare as the proxy, allowlist Cloudflare IP addresses at the origin, then teach the web server to use CF-Connecting-IP (or log the header explicitly).

When responding to requests and logging them, your origin server returns a Cloudflare IP address. The original visitor IP address appears in an appended HTTP header called CF-Connecting-IP. By following our web server instructions, you can log the original visitor IP address at your origin server.

— Cloudflare, Restoring original visitor IPs

Cloudflare no longer maintains mod_cloudflare on current Debian/Ubuntu releases and recommends mod_remoteip for Apache with RemoteIPHeader CF-Connecting-IP and trusted proxies listed from Cloudflare IPs. For Nginx, use ngx_http_realip_module with set_real_ip_from for each Cloudflare range and real_ip_header CF-Connecting-IP; (or, less ideally, X-Forwarded-For). Step-by-step snippets live under Restoring original visitor IPs (Apache, Nginx, IIS, Tomcat, HAProxy, Caddy, and others).

A small PHP snippet can set $_SERVER['REMOTE_ADDR'] from HTTP_CF_CONNECTING_IP for application code, but it does not rewrite web server access logs—module or log-format changes are still required for accurate files.

Cloudflare Tunnel: visitor IP does not reach the origin by default

Section titled “Cloudflare Tunnel: visitor IP does not reach the origin by default”

No. When using Cloudflare Tunnel, all requests to the origin are made internally between cloudflared and the origin. To log external visitor IPs, you will need to configure an alternative method.

— Cloudflare, Cloudflare Tunnels FAQ

Request forwarding quirks that affect headers

Section titled “Request forwarding quirks that affect headers”

Cloudflare may drop request header names NGINX considers invalid (for example names containing .). On responses to visitors, Cloudflare can remove headers such as Cache-Tag and add its own; Cloudflare Pages adds response headers including Cf-Ray and Server: cloudflare when serving assets.

Cloudflare may remove Content-Length on responses to visitors unless the origin sends cache-control: no-transform. See Content compression and Troubleshoot Rules.

Browser Run attaches headers so destination servers can identify Cloudflare-originated browser automation requests.

Common mistakes when using visitor IP headers

Section titled “Common mistakes when using visitor IP headers”
  • Trusting X-Forwarded-For without validating the proxy path — Prefer CF-Connecting-IP or True-Client-IP for a single authoritative client IP when traffic comes only from Cloudflare.
  • Blocking Cloudflare IPs at the origin — Firewall or security plugins that reject Cloudflare ranges break the proxy; allowlist ranges from Cloudflare IP addresses.
  • Expecting CF-Connecting-IP through Tunnel — Use a documented alternative for external visitor IP logging (Tunnels FAQ).
  • Spoofing risk on stacked CDNs — Use Managed Transforms and understand Remove visitor IP headers behaviour before relying on X-Forwarded-For for security decisions (Managed Transforms reference).
  • Relying on mod_cloudflare on modern Apache — Migrate to mod_remoteip per Restoring original visitor IPs.
  1. Send a test request through the proxied hostname and confirm the origin receives CF-Connecting-IP (or True-Client-IP if enabled) using your server or app logs. If missing, review Managed Transforms and Cloudflare HTTP headers.

  2. Compare the logged client IP with the value in CF-Connecting-IP after configuring Apache mod_remoteip or Nginx real_ip_module per Restoring original visitor IPs.

  3. Add Cf-Ray to access logs using the Apache or Nginx examples in Gathering information for troubleshooting sites, then confirm the response header matches your log field.

  4. If geolocation is required, enable IP Geolocation or Add visitor location headers and verify cf-ipcountry (or extended cf-* headers) at the origin.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about, and we will correct or clarify it.