Setting up Cloudflare CDN for 1C-Bitrix
Site on Bitrix serves static files (JS, CSS, images) from same server as PHP. Over 50–100 RPS load server starts choking — not because PHP is slow but because Nginx is busy serving files. Cloudflare CDN removes this load: static served from nearest edge server while origin handles only dynamics.
What to cache and what not to
Cloudflare by default caches files by extension: .js, .css, .jpg, .png, .woff2, .svg and others. HTML and PHP not cached. For Bitrix this is correct behavior — dynamic pages must generate on server.
Exceptions to configure via Page Rules or Cache Rules:
-
/upload/resize_cache/— cache it. These are image resizes, don't change after generation. -
/bitrix/cache/— don't cache. Bitrix internal cache, not intended for CDN. -
/bitrix/admin/*— bypass. Admin panel must not be cached. -
/personal/*,/auth/*— bypass. Personal account, auth forms.
Setting up cache headers
Bitrix by default doesn't set optimal Cache-Control for static files. Nginx usually configured with expires 30d for /upload/ and /bitrix/images/. Cloudflare respects these headers — if server sends Cache-Control: max-age=2592000, Cloudflare caches file for 30 days.
Check Nginx configuration:
location ~* \.(js|css|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
Directive immutable tells browser file won't change — browser won't send conditional request (If-Modified-Since). For Bitrix this is correct because Vite/webpack adds hash to filename on each build.
Browser Cache TTL and Edge Cache TTL
Browser Cache TTL — how long browser stores file locally. Set in Cloudflare Dashboard → Caching → Browser Cache TTL. Recommendation: "Respect Existing Headers" — let Nginx manage.
Edge Cache TTL — how long Cloudflare stores file on its servers. By default determined by origin headers. Via Page Rules override: for /upload/ set Edge Cache TTL = 1 month.
Minification and optimization
Cloudflare offers Auto Minify for JS, CSS and HTML. For Bitrix disable HTML minification — it may break <script> inserts in components and inline styles. JS and CSS minification can stay but if you already minify at build stage (Vite, webpack) — Cloudflare minify adds no benefit and only delays on edge.
Polish (image optimization) — enable it. Compresses JPEG and PNG losslessly/lossy. For catalogs with thousands of product photos bandwidth savings reach 20–30%.
Brotli compression — enable it. Cloudflare compresses text responses (HTML, JS, CSS) with Brotli algorithm which is 15–20% more efficient than gzip.
Verifying CDN operation
After setup verify response headers for static file:
-
cf-cache-status: HIT— file served from Cloudflare cache. -
cf-cache-status: MISS— file requested from origin (first request or cache expired). -
cf-cache-status: DYNAMIC— Cloudflare doesn't cache this resource (HTML, PHP).
If you see DYNAMIC for .js or .css — check origin doesn't send Cache-Control: no-store or Set-Cookie. Cloudflare doesn't cache responses with Set-Cookie and Bitrix may set session cookie on any request. Make sure Nginx handles static requests directly without passing to PHP.







