Restoring original visitor IPs·续
Tomcat 7
To have Tomcat7 automatically restore the original visitor IP to your access logs and application you will need to add %{CF-Connecting-IP}i into your log schema.
As an example, you could add the below block to your server.xml file.
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%{CF-Connecting-IP}i - %h %u %t - "%r" - %s - %b - %{CF-RAY}i"/>
Which would result in your logs looking like this:
Visitor IP - Cloudflare IP - [04/Dec/2014:23:18:15 -0500] - "GET / HTTP/1.1" - 200 - 1895 - 193d704b85200296-SJC
Magento
Refer to this third-party tutorial on restoring original visitor IP with Magento and Cloudflare ↗︎.
Similarly, Cloudflare did not write this Magento extension ↗︎, but some of our customers have found it helpful.
As this plugin was created by an outside party, we can't provide technical support for issues related to the plugin.
IPB (Invision Power Board)
To enable correct IP matching when running an Invision Power Board 3 installation through Cloudflare, follow these directions:
Log into your IPB installation's ACP.
- Click System.
- Under Overview, click Security.
- Under Security Center, click Security Settings.Check that Trust IP addresses provided by proxies? is green.
IPB4 description of Trust IP addresses provided by proxies?
If your network environment means requests are handled through a proxy (such as in an intranet situation in an office or university, or on a load-balanced server cluster), you may need to enable this setting so that the correct IP address is used. However, when enabled, a malicious user can abuse the system to provide a fake IP address. In most environments, this setting should be left off.
PHPBB
If you are using an Apache server, then we would recommend installing mod_remoteip ↗︎ to restore the visitor IP back to your logs.
If you do not have access to your server to install a mod, then you may be able to modify the core ↗︎.
MyBB forums
More recent versions of MyBB include a Scrutinize User's IP address option.
Admin CP > Configuration > Server and Optimization Options > Scrutinize User's IP address? > Yes
Alternatively, you may install the Cloudflare management plugin ↗︎ available for MyBB 1.6.
MyBB 1.6.0, 1.6.1, 1.6.2, or 1.6.3
- Navigate to
./inc/functions.php. - Go to line 2790.
- Replace:
if(isset($_SERVER['REMOTE_ADDR']))With:if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])) - Then, replace:
$ip = $_SERVER['REMOTE_ADDR'];With:$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
Vanilla forums
A member of the Vanilla team has written a Cloudflare plugin for Vanilla ↗︎ to restore original visitor IP to the log files for self-hosted sites.
As this plugin was created by an outside party, we can't provide technical support for issues related to the plugin.MediaWiki
- Open
includes/GlobalFunctions.php. At approximately line 370, change the following:$forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";to$forward = "\t(proxied via {$_SERVER['HTTP_CF_CONNECTING_IP']}{$forward})"; - Open
includes/ProxyTools.php. At approximately line 79, find:if ( isset( $_SERVER['REMOTE_ADDR'] ) ){and replace with:if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ){The second step only applies to MediaWiki versions 1.18.0 and older. Newer versions of MediaWiki have completely rewritten ProxyTools.php and the following code is no longer present. - Find at approximately line 80:
$ipchain = array( IP::canonicalize($_SERVER['REMOTE_ADDR']) );Save and upload to your origin web server.
For versions around 1.27.1:
- Go to line 1232 in
GlobalFunctions.php, changeREMOTE_ADDRtoHTTP_CF_CONNECTING_IP. - Next, go to
WebRequest.php, in lines 1151 to line 1159, changeREMOTE_ADDRtoHTTP_CF_CONNECTING_IP.
XenForo
A XenForo user has created a plugin for Cloudflare ↗︎.
As this plugin was created by an outside party, we can't provide technical support for issues related to the plugin.
- Open
library/config.php. - At the end, add:
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];} - Upload and overwrite.
PunBB
An outside party has created a module for Cloudflare and PunBB ↗︎ that will restore original visitor IP.
As this plugin was created by an outside party, we can't provide technical support for issues related to the plugin.Cherokee server
- Launch
cherokee-adminon your server. - Navigate to the Cherokee Administration interface in your web browser.
- Select the Virtual Server for the domain that is being serviced by Cloudflare.
- On the Logging tab for your selected Virtual Server, enable Accept Forwarded IPs.
- In the Accept from Hosts box, enter Cloudflare's IP addresses ↗︎.
Livezilla
You can fix the IP address by changing the PHP IP Server Param field on the Livezilla server configuration to HTTP_CF_CONNECTING_IP.
Datalife Engine
To restore visitor IP to DataLife Engine:
- Open:/engine/inc/include/functions.inc.phpFind:
$db_ip_split = explode( ".", $_SERVER['REMOTE_ADDR'] );Change to:$db_ip_split = explode(".", $_SERVER['HTTP_CF_CONNECTING_IP'] ); - Find:
$ip_split = explode( ".", $_SERVER['REMOTE_ADDR'] );Change to:$ip_split = explode(".", $_SERVER['HTTP_CF_CONNECTING_IP'] ); - Open:/engine/modules/addcomments.phpFind:
$_SERVER['REMOTE_ADDR'],Change to:$_SERVER['HTTP_CF_CONNECTING_IP'], - Find:
$db_ip_split = explode( ".", $_SERVER['REMOTE_ADDR'] );Change to:$db_ip_split = explode( ".", $_SERVER['HTTP_CF_CONNECTING_IP'] );
TYPO3
An outside developer has created a Cloudflare extension for TYPO3 ↗︎ that will restore original visitor IP to your logs. The extension will also give the ability to clear your Cloudflare cache.
As this plugin was created by an outside party, we can't provide technical support for issues related to the plugin.
VestaCP
If you use the hosting control panel VestaCP, you have both Nginx and Apache running on your server. Requests are proxied through Nginx before going to Apache.
Because of this Nginx proxy, you actually need to follow the instructions to configure Nginx to return the real visitor IP address. mod_remoteip ↗︎ for Apache is not needed unless you disable the Nginx server for some requests. Adding mod_remoteip ↗︎ to Apache will not conflict with the Nginx server configuration.
node.js
An outside developer has created a module to restore visitor IP called node_cloudflare. ↗︎
HAProxy
In order to extract the original client IP in the X_FORWARDED_FOR header, you need to use the following configuration in HAProxy:
- Create a text file
CF_ips.lstcontaining all IP ranges from https://www.cloudflare.com/en-gb/ips/ ↗︎ - Ensure to disable
option forwardforin HAProxy
HAProxy config:
acl from_cf src -f /path/to/CF_ips.lst
acl cf_ip_hdr req.hdr(CF-Connecting-IP) -m found
http-request set-header X-Forwarded-For %[req.hdr(CF-Connecting-IP)] if from_cf cf_ip_hdr
Envoy Gateway
To extract the original client IP for your Envoy Gateway, set a Client Traffic Policy ↗︎ to look for the custom CF-Connecting-IP header.
Truncated Client Traffic Policy exampletxt
clientIPDetection:
customHeader:
name: CF-Connecting-IP
failClosed: true
For more details, refer to Custom header original IP detection extension ↗︎.
Caddy
If you are running an application behind Caddy ↗︎ that relies on the X-Forwarded-For header, you can configure Caddy to override the header with Cloudflare's CF-Connecting-IP header.
It is advised that you also only accept traffic from Cloudflare's IP addresses ↗︎; otherwise, the header could be spoofed. That's why, in the second example, we handle this as part of the Caddy configuration. Alternatively, you can handle this at the firewall level, which is usually easier to automate. If you already have a firewall or other measure in place to ensure this, your Caddyfile could look like this:
Caddyfiletxt
https://example.com {
reverse_proxy localhost:8080 {
# Sets X-Forwarded-For as the value Cloudflare gives us for CF-Connecting-IP.
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
}
}
If you want Caddy to handle only accepting traffic from Cloudflare's IP addresses ↗︎, you can use a configuration like this one:
Caddyfiletxt
https://example.com {
# Restrict access to Cloudflare IPs (https://www.cloudflare.com/ips/)
@cloudflare {
remote_ip 173.245.48.0/20 103.21.244.0/22 103.22.200.0/22 103.31.4.0/22 141.101.64.0/18 108.162.192.0/18 190.93.240.0/20 188.114.96.0/20 197.234.240.0/22 198.41.128.0/17 162.158.0.0/15 104.16.0.0/13 104.24.0.0/14 172.64.0.0/13 131.0.72.0/22 2400:cb00::/32 2606:4700::/32 2803:f800::/32 2405:b500::/32 2405:8100::/32 2a06:98c0::/29 2c0f:f248::/32
}
# Process requests from Cloudflare IPs
handle @cloudflare {
reverse_proxy localhost:8080 {
# Sets X-Forwarded-For as the value Cloudflare gives us for CF-Connecting-IP.
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
}
}
# Deny requests from non-Cloudflare IPs
handle {
respond "Access Denied" 403
}
}
Related Resources
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/#page","headline":"Restoring original visitor IPs","description":"Configure your server to log original visitor IPs.","url":"https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/","inLanguage":"en","image":"https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/og.png?v=05a70f3d23294eb7","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Check Cloudflare service status and configure notifications. title: Cloudflare Status image: https://developers.cloudflare.com/support/cloudflare-status/og.png?v=c4bae81cb2717e2b
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/support/llms.txt
Use this file to discover all available pages before exploring further.
Docs