Routing a XenForo forum through Cloudflare accelerates static asset delivery, absorbs volumetric DDoS attacks, and filters automated bot traffic before it reaches PHP or MySQL. However, running Cloudflare with default proxy settings masks visitor IP addresses and can disrupt AdminCP sessions unless specific cache rules and server headers are configured.
Restoring Real Visitor IP Addresses
When Cloudflare proxies incoming traffic, your origin server sees Cloudflare's edge node IPs instead of the visitor's actual address. If left uncorrected, every member and spammer shares the same IP range in XenForo's logs, breaking flood checks, multi-account detection, and IP bans.
The cleanest solution is configuring ngx_http_realip_module in Nginx or mod_remoteip in Apache to trust Cloudflare's published IP ranges and read the CF-Connecting-IP header. If you are on managed hosting without web server configuration access, add the following snippet to src/config.php so XenForo logs the true client address:
Configuring Cache Rules and Disabling Rocket Loader
Never apply a blanket "Cache Everything" rule across a forum domain without cookie exclusions, as doing so can serve cached HTML pages containing another member's private alerts or session state. Instead, configure targeted Cache Rules in your Cloudflare dashboard:
Enabling Cloudflare Turnstile CAPTCHA
XenForo includes native integration for Cloudflare Turnstile, allowing you to block automated registration bots without forcing legitimate visitors through frustrating image puzzles. Log into your Cloudflare dashboard, open the Turnstile tab, and create a new widget for your forum domain to generate a Site Key and Secret Key.
Next, open AdminCP > Setup > Options > Basic options in XenForo, scroll to the Enable CAPTCHA for guests setting, select Cloudflare Turnstile, and paste both keys into their respective fields before saving.
Restoring Real Visitor IP Addresses
When Cloudflare proxies incoming traffic, your origin server sees Cloudflare's edge node IPs instead of the visitor's actual address. If left uncorrected, every member and spammer shares the same IP range in XenForo's logs, breaking flood checks, multi-account detection, and IP bans.
The cleanest solution is configuring ngx_http_realip_module in Nginx or mod_remoteip in Apache to trust Cloudflare's published IP ranges and read the CF-Connecting-IP header. If you are on managed hosting without web server configuration access, add the following snippet to src/config.php so XenForo logs the true client address:
Kod:
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}Configuring Cache Rules and Disabling Rocket Loader
Never apply a blanket "Cache Everything" rule across a forum domain without cookie exclusions, as doing so can serve cached HTML pages containing another member's private alerts or session state. Instead, configure targeted Cache Rules in your Cloudflare dashboard:
- Static Asset Caching: Match URI paths starting with /data/, /styles/, and /js/ and set the Edge Cache TTL to 1 month to offload avatar, attachment, and stylesheet bandwidth from your origin server.
- Admin and Session Bypass: Create a bypass rule for /admin.php* and any request containing the xf_user cookie so authenticated members always receive live dynamic responses.
- Disable Rocket Loader: Navigate to Speed > Optimization > Content Optimization and ensure Rocket Loader is turned off, as asynchronous script rewriting frequently breaks XenForo's JavaScript event listeners and rich-text editor.
Enabling Cloudflare Turnstile CAPTCHA
XenForo includes native integration for Cloudflare Turnstile, allowing you to block automated registration bots without forcing legitimate visitors through frustrating image puzzles. Log into your Cloudflare dashboard, open the Turnstile tab, and create a new widget for your forum domain to generate a Site Key and Secret Key.
Next, open AdminCP > Setup > Options > Basic options in XenForo, scroll to the Enable CAPTCHA for guests setting, select Cloudflare Turnstile, and paste both keys into their respective fields before saving.