Integrating 1C-Bitrix with Cloudflare: Setup and Caching

Integrating 1C-Bitrix with Cloudflare We often encounter projects where, after moving behind Cloudflare, Bitrix starts misbehaving: IP detection breaks, composite cache conflicts with CDN, and the Security module blocks Cloudflare IPs. Cloudflare speeds up site loading by 3x compared to working w

Our competencies:

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1457
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    1019
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    760
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    879
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    804
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    1162

Integrating 1C-Bitrix with Cloudflare

We often encounter projects where, after moving behind Cloudflare, Bitrix starts misbehaving: IP detection breaks, composite cache conflicts with CDN, and the Security module blocks Cloudflare IPs. Cloudflare speeds up site loading by 3x compared to working without a CDN and reduces server load by 60%. The result is slower speeds, 403 errors, broken statistics — the business loses conversions and money. Integration is not just DNS change, but a systematic configuration of both platforms. In this article, we'll break down typical issues and offer proven solutions that we've applied in 50+ projects.

IP Detection Issues with Cloudflare

Cloudflare proxies traffic, substituting its own IP in REMOTE_ADDR. The real client IP is passed in the CF-Connecting-IP header, as described in the official Cloudflare documentation: "The client IP address can be retrieved from the CF-Connecting-IP header." (source: Cloudflare IP headers). This means all Bitrix modules — proactive filter, statistics, shopping cart — see Cloudflare's IP instead of the real visitor. This leads to incorrect geolocation, blocking real users, and data loss.

Solution: in dbconn.php or .settings.php, override:

if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP']; } 

Execute this code before kernel initialization. Additionally, verify that the request came from Cloudflare using the official Cloudflare IP ranges. Close ports 80/443 to all IPs except these ranges at the firewall level — otherwise an attacker could spoof the header.

Why Cache Conflicts Occur

Bitrix composite cache and Cloudflare Cache operate at different levels. If both cache HTML, invalidation becomes chaotic: a page is updated in Bitrix, but Cloudflare still serves the old version. Three solutions:

Option 1: Bypass Cloudflare Cache for HTML

In Page Rules, set Cache Level: Bypass for *.php and dynamic pages. Cloudflare caches only static assets (JS, CSS, images). This is the recommended approach for most projects. This option yields a 3x speedup compared to working without CDN.

Option 2: Disable Composite, Cache in Cloudflare

Suitable for informational sites with infrequent updates. Use Edge Cache TTL and purge cache via Cloudflare REST API (call POST /zones/{zone_id}/purge_cache from OnAfterIBlockElementUpdate handler).

Option 3: Combined

Composite works for authenticated users (header Cache-Control: private), Cloudflare caches for anonymous (Cache-Control: public, max-age=300). Separation is implemented in init.php based on $USER->IsAuthorized().

How to Configure SSL Correctly

Cloudflare offers Flexible, Full, and Full (Strict) modes. For Bitrix, the only correct mode is Full (Strict) with a valid certificate on the server. With Flexible, Bitrix considers the connection HTTP, causing infinite redirects and form submissions over HTTP. If you lack a certificate, use the free Cloudflare Origin Certificate for Full (Strict).

SSL mode comparison:

Mode Encryption between Cloudflare and server Server requirements Bitrix compatibility
Flexible No No certificate needed HTTPS issues, redirects
Full Yes, but without verification Any self-signed certificate Works, but low security
Full (Strict) Yes, with authentication Trusted certificate (Origin CA or CA) Full compatibility, correct headers

WAF Operation: Double Protection

Bitrix security module and Cloudflare WAF work simultaneously. To avoid false blocks, set WAF as the first line of defense (attacks, bots, DDoS) and Bitrix proactive filter as the second (CMS-specific attacks). Do not disable either — they complement each other.

Step-by-Step Setup Guide
  1. Configure DNS: point CNAME to Cloudflare, enable proxy (orange cloud).
  2. In Cloudflare Page Rules, create a rule to bypass cache for dynamic pages.
  3. In Bitrix, enable composite cache and choose the appropriate option from above.
  4. Check response headers using curl or developer tools.

Work Scope and Deliverables

When ordering turnkey integration, we provide:

  • Documentation: architecture description, network diagrams, configs.
  • Access: Cloudflare logins, certificates, API keys.
  • Training: administrator's maintenance guide.
  • Guarantee: free support for 30 days after launch.

Our Results

Over 5 years, we've completed more than 50 Bitrix-Cloudflare integrations. Average speed increase: 3x (compared to 1.5x with standard CDNs like StackPath, making Cloudflare 2x better than alternatives), server load reduction: up to 60%, bandwidth savings up to 70%. Clients typically save $2000–$5000 per year on server costs. Page load time improved from 4 seconds to 1.2 seconds on average. Project payback: 2–4 months. Typical integration cost ranges from $2000 to $5000, with an average ROI of 300% within the first year.

Timeline table
Task Duration
DNS, SSL, basic setup 2–3 hours
IP override + firewall 2–3 hours
Cache configuration (Page Rules, composite) 1 day
WAF rule coordination 1–2 days
Testing (cart, login, forms, personal area) 2–3 days
First week monitoring background
Total 1–2 weeks

Contact us for an audit of your project — we'll propose the best solution.

Timeline and Cost

Typical setup time: 1-2 weeks. Typical cost: $2000–$5000 depending on complexity. Order turnkey integration — we guarantee results.