{"id":1273,"date":"2026-11-17T17:36:20","date_gmt":"2026-11-17T12:06:20","guid":{"rendered":"https:\/\/merahost.org\/blog\/configuring-litespeed-web-server-with-cloudflare-preventing-real-ip-masking-and-cache-collisions\/"},"modified":"2026-11-17T17:36:20","modified_gmt":"2026-11-17T12:06:20","slug":"configuring-litespeed-web-server-with-cloudflare-preventing-real-ip-masking-and-cache-collisions","status":"publish","type":"post","link":"https:\/\/merahost.org\/blog\/configuring-litespeed-web-server-with-cloudflare-preventing-real-ip-masking-and-cache-collisions\/","title":{"rendered":"Configuring LiteSpeed Web Server with Cloudflare: Preventing Real IP Masking and Cache Collisions"},"content":{"rendered":"<p>Deploying an enterprise reverse proxy network in front of a high-performance LiteSpeed Web Server (LSWS) stack frequently introduces severe architectural anomalies if the proxy-to-origin transport boundary is misconfigured. When Cloudflare terminates inbound edge connections and routes requests to LiteSpeed without rigorous origin trust validation, security controls become blinded by real IP masking, while uncoordinated caching policies trigger catastrophic cache collisions between edge CDN nodes and origin LSCache engines. Engineering a resilient, deterministic content delivery pipeline requires synchronized IP unwrapping, strict header sanitization, and automated dual-tier cache purge propagation on <a href=\"https:\/\/merahost.org\">MeraHost<\/a> high-performance infrastructure.<\/p>\n<p><!-- more --><\/p>\n<h2>The Mechanics of Cloudflare and LiteSpeed Integration: Resolving the Dual-Proxy Dilemma<\/h2>\n<div class=\"wp-block-group\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:20px;margin:24px 0;border-radius:0 4px 4px 0\">\n<p style=\"margin:0;font-size:15px;line-height:1.6;color:#333\"><strong>Direct Answer:<\/strong> To optimize a cloudflare with litespeed cache configuration, configure LiteSpeed&#8217;s <code>Use Client IP in Header<\/code> directive to <code>Trusted IP Only<\/code>, register Cloudflare&#8217;s official IP ranges in <code>httpd_config.conf<\/code>, and disable edge caching for personalized HTML. This restores authentic visitor IPs in <code>REMOTE_ADDR<\/code>, prevents security bypasses, and stops cache collisions between Cloudflare edge nodes and origin LSCache.<\/p>\n<\/div>\n<p>Modern web infrastructure combines globally distributed Content Delivery Networks (CDNs) with high-efficiency origin web servers to achieve sub-second Time to First Byte (TTFB) and robust volumetric DDoS protection. Cloudflare sits at the edge, intercepting DNS queries and terminating client TLS connections across hundreds of Points of Presence (PoPs). Downstream, LiteSpeed Web Server operates as the authoritative origin engine, leveraging event-driven asynchronous I\/O and kernel-level page caching via its proprietary shared-memory architecture.<\/p>\n<p>However, introducing a reverse proxy disrupts the classic end-to-end client-server relationship. By default, every TCP handshake received by LiteSpeed originates from an Anycast IP address belonging to Cloudflare rather than the actual visitor&#8217;s device. Simultaneously, both Cloudflare and LiteSpeed feature independent caching subsystems. Without deliberate coordination, this dual-caching paradigm causes session cross-contamination, stale content delivery, and broken security heuristics.<\/p>\n<h2>Anatomy of the Real IP Masking Vulnerability<\/h2>\n<p>When an HTTP request traverses Cloudflare, the edge server modifies the TCP packet headers. The source IP address in the IP header is rewritten to Cloudflare&#8217;s egress interface. To preserve the visitor&#8217;s identity for origin logging and application logic, Cloudflare appends custom HTTP headers:<\/p>\n<ul>\n<li><code>CF-Connecting-IP<\/code>: Contains the 64-bit or 128-bit raw IP address of the client that initiated the connection to Cloudflare.<\/li>\n<li><code>X-Forwarded-For<\/code>: A comma-delimited chain of proxy IP addresses, with the client IP prepended.<\/li>\n<li><code>CF-Ray<\/code>: A unique hash identifier representing the request context, data center location, and edge transit trace.<\/li>\n<li><code>CF-Visitor<\/code>: A JSON payload indicating the client connection scheme (HTTP or HTTPS).<\/li>\n<\/ul>\n<p>If LiteSpeed is left unconfigured, its internal environment variable <code>REMOTE_ADDR<\/code> reflects Cloudflare&#8217;s proxy nodes. This produces four immediate operational hazards:<\/p>\n<ol>\n<li><strong>Security Suite Blindness:<\/strong> Web Application Firewalls (such as ModSecurity, Imunify360, and CSF\/LFD) evaluate incoming traffic based on <code>REMOTE_ADDR<\/code>. A single malicious actor triggering a brute-force threshold will cause the origin firewall to ban a Cloudflare Anycast IP, inadvertently cutting off thousands of legitimate users routed through that same PoP.<\/li>\n<li><strong>Rate Limiting Failure:<\/strong> LiteSpeed&#8217;s native per-client connection limits (Anti-DDoS Throttling) will group hundreds of concurrent connections into a single Cloudflare IP, prematurely triggering connection drops or throttling legitimate client requests.<\/li>\n<li><strong>Header Injection Exploits:<\/strong> If a system administrator enables LiteSpeed&#8217;s <code>Use Client IP in Header<\/code> globally (setting it to <code>Yes<\/code> \/ value <code>1<\/code>), LiteSpeed blindly trusts any incoming <code>X-Forwarded-For<\/code> header from any host. An attacker who bypasses Cloudflare and reaches the origin server directly on port 80 or 443 can forge <code>X-Forwarded-For: 127.0.0.1<\/code> to gain unauthorized administrative privileges.<\/li>\n<li><strong>Corrupted Analytics &amp; Compliance:<\/strong> Server access logs and e-commerce payment gateways record proxy addresses, violating GDPR\/PCI-DSS auditing requirements and breaking GeoIP localization.<\/li>\n<\/ol>\n<blockquote class=\"wp-block-quote\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:16px 20px;margin:24px 0\">\n<p><strong style=\"color:#001b41\">Architecture Note on Proxy Header Spoofing:<\/strong> Never set LiteSpeed&#8217;s <code>Use Client IP in Header<\/code> to <code>1<\/code> (Yes\/All). Enabling global header extraction allows malicious actors who bypass Cloudflare by sending direct HTTP requests to your origin IP to forge the <code>X-Forwarded-For<\/code> header with <code>127.0.0.1<\/code> or legitimate admin addresses. Always enforce value <code>2<\/code> (Trusted IP Only) and strictly validate upstream proxy CIDR blocks.<\/p>\n<\/blockquote>\n<h2>Architecture Comparison: Default vs. Tuned Production<\/h2>\n<p>The comparative matrix below illustrates the systemic differences between an ad-hoc integration and a hardened enterprise deployment of Cloudflare and LiteSpeed Web Server.<\/p>\n<figure class=\"wp-block-table is-style-regular\">\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;font-size:15px;text-align:left\">\n<thead style=\"background:#001b41;color:#ffffff\">\n<tr>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Feature \/ Metric<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Standard \/ Default<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Tuned \/ Production<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Client IP Resolution<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Cloudflare Edge IP (Masked)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Authentic Client IPv4\/IPv6 Unwrapped<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">IP Header Spoofing Risk<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">High (Arbitrary XFF Injection)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Zero (Enforced Trusted Proxy CIDRs)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Rate Limiting &amp; Fail2ban<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Accidental Banning of Cloudflare Nodes<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Granular Per-Client Enforcement<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Cache Architecture<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Unsynchronized Dual-Layer Collision<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Segregated Edge Static \/ Origin LSCache Dynamic<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Cart &amp; Session Isolation<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Frequent Dynamic Leakage<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Vary: Cookie &amp; ESI Injection Segregation<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Cache Invalidation Latency<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Manual Multi-Dashboard Purges<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Automated Tag-Based API Invalidation (&lt; 150ms)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Origin TTFB (Dynamic Hits)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">280ms &#8211; 650ms<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">12ms &#8211; 35ms (Pure NVMe Shared Memory)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h2>The Cache Collision Problem: When CDN and LSCache Collide<\/h2>\n<p>The second operational challenge in a hybrid Cloudflare-LiteSpeed architecture is cache collision. Both platforms incorporate high-speed caching engines, but their operational scopes and eviction behaviors differ fundamentally:<\/p>\n<ul>\n<li><strong>Cloudflare Edge Cache:<\/strong> Globally distributed across hundreds of data centers. By default, it caches static assets (CSS, JS, images, media) based on file extensions. However, administrators frequently configure &#8220;Cache Everything&#8221; Page Rules or Cache Rules to cache entire HTML pages at the edge to achieve near-instantaneous global response times.<\/li>\n<li><strong>LiteSpeed Cache (LSCache):<\/strong> Resides in shared memory on the origin server. It understands WordPress, Magento, and WooCommerce application states, parsing cookies, user login tokens, nonces, and dynamic session data. It uses micro-caching and granular cache tags (<code>X-LiteSpeed-Cache-Control<\/code> and <code>X-LiteSpeed-Tag<\/code>) to purge specific pages, categories, or widgets instantly when content changes.<\/li>\n<\/ul>\n<p>When Cloudflare is configured to cache HTML pages without native awareness of LiteSpeed&#8217;s cache tags, three critical failure modes occur:<\/p>\n<h3>1. Dynamic Content Staling and De-synchronized Purges<\/h3>\n<p>When an author publishes a blog post or edits a WooCommerce product, LSCache purges the corresponding cache entry in LiteSpeed shared memory within milliseconds. However, Cloudflare&#8217;s edge PoPs are unaware of this local event. Cloudflare continues to serve the cached HTML from its edge servers for the duration of the Edge Cache TTL (often hours or days). Visitors receive stale pages until an administrator manually issues an edge purge via the Cloudflare dashboard or API.<\/p>\n<h3>2. The E-Commerce Cart Session Collision<\/h3>\n<p>In high-concurrency e-commerce environments, a naive &#8220;Cache Everything&#8221; rule will capture a page generated for an authenticated customer or a customer with active cart items. If the response lacks explicit <code>Vary: Cookie<\/code> directives or private cache-control headers, Cloudflare stores the personalized HTML. The next visitor requesting the same URL receives the cached payload\u2014revealing another customer&#8217;s cart contents, name, and CSRF nonces. This is a severe data privacy breach and security failure.<\/p>\n<blockquote class=\"wp-block-quote\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:16px 20px;margin:24px 0\">\n<p><strong style=\"color:#001b41\">E-Commerce Integrity Warning:<\/strong> When running WooCommerce or Magento behind Cloudflare, never deploy a blanket &#8220;Cache Everything&#8221; Page Rule without rigorous bypass cookies (<code>woocommerce_items_in_cart<\/code>, <code>wp_woocommerce_session_<\/code>). Failure to isolate cart states results in session bleeding, where customers see each other&#8217;s carts and checkout forms\u2014a critical security and compliance violation.<\/p>\n<\/blockquote>\n<h3>3. Vary Header Stripping and ESI Incompatibility<\/h3>\n<p>LiteSpeed utilizes Edge Side Includes (ESI) to puncture holes in cached pages, allowing public content to be served from static shared memory while personal widgets (such as a shopping cart badge or login greeting) are assembled dynamically on the fly. Cloudflare&#8217;s standard CDN pipeline does not execute origin ESI tags. If Cloudflare caches the raw response before ESI assembly, visitors receive raw <code>&lt;esi:include&gt;<\/code> markup or empty placeholders.<\/p>\n<h2>Production Implementation: Hardening LiteSpeed for Cloudflare<\/h2>\n<p>To eliminate real IP masking and resolve cache collisions permanently, deploy the following production configurations across your LiteSpeed server and automation pipelines.<\/p>\n<h3>Step 1: Configure LiteSpeed Server IP Validation<\/h3>\n<p>In the LiteSpeed WebAdmin Console (or directly in <code>\/usr\/local\/lsws\/conf\/httpd_config.conf<\/code>), enable trusted proxy header processing. Set <code>useIpInProxyHeader<\/code> to <code>2<\/code> (Trusted IP Only). This instructs LiteSpeed to extract the real visitor IP from headers like <code>CF-Connecting-IP<\/code> and <code>X-Forwarded-For<\/code> ONLY when the connecting TCP peer matches an authorized subnet.<\/p>\n<p>Below is the declarative configuration block for <code>\/usr\/local\/lsws\/conf\/httpd_config.conf<\/code>:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/usr\/local\/lsws\/conf\/httpd_config.conf\n# Enforce Trusted Proxy IP Resolution for Cloudflare\n\nuseIpInProxyHeader            2\n\n# Define Trusted Cloudflare IPv4 &amp; IPv6 Subnets\n# Direct handshake validation prevents header injection\naccessControl  {\n  allow                       ALL, 173.245.48.0\/20T, 103.21.244.0\/22T, 103.22.200.0\/22T, 103.31.4.0\/22T, 141.101.64.0\/18T, 108.162.192.0\/18T, 190.93.240.0\/20T, 188.114.96.0\/20T, 197.234.240.0\/22T, 198.41.128.0\/17T, 162.158.0.0\/15T, 104.16.0.0\/13T, 104.24.0.0\/14T, 172.64.0.0\/13T, 131.0.72.0\/22T, 2400:cb00::\/32T, 2606:4700::\/32T, 2803:f800::\/32T, 2405:b500::\/32T, 2405:8100::\/32T, 2a06:98c0::\/29T, 2c0f:f248::\/32T\n}<\/code><\/pre>\n<p>The <code>T<\/code> suffix at the end of each CIDR subnet is LiteSpeed&#8217;s proprietary trust flag. It tells the web server that connections originating from these IP ranges are trusted reverse proxies, permitting the real client IP in the proxy header to overwrite <code>REMOTE_ADDR<\/code>.<\/p>\n<h3>Step 2: Automated Cloudflare IP Synchronization Daemon<\/h3>\n<p>Cloudflare periodically expands its global network and allocates new IP prefixes. Statically hardcoding subnets in server configs risks service disruption if Cloudflare introduces a new range that LiteSpeed does not recognize as trusted. Deploy an automated cron or systemd timer script to synchronize official Cloudflare IP ranges directly into LiteSpeed&#8217;s configuration.<\/p>\n<p>Save the following bash script to <code>\/usr\/local\/bin\/sync-cloudflare-lsws-ips.sh<\/code> and grant execute permissions (<code>chmod +x<\/code>):<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>#!\/usr\/bin\/env bash\n# \/usr\/local\/bin\/sync-cloudflare-lsws-ips.sh\n# Enterprise Cloudflare IP Syncer for LiteSpeed Web Server\nset -euo pipefail\n\nCONF_FILE=\"\/usr\/local\/lsws\/conf\/httpd_config.conf\"\nBACKUP_DIR=\"\/usr\/local\/lsws\/conf\/backups\"\nTIMESTAMP=$(date +\"%Y%m%d_%H%M%S\")\n\nmkdir -p \"${BACKUP_DIR}\"\n\n# Fetch official IPv4 and IPv6 CIDR lists\nIPV4_URL=\"https:\/\/www.cloudflare.com\/ips-v4\"\nIPV6_URL=\"https:\/\/www.cloudflare.com\/ips-v6\"\n\nCF_IPS=()\nwhile IFS= read -r line; do\n    [[ -n \"$line\" ]] &amp;&amp; CF_IPS+=(\"${line}T\")\ndone &lt; &lt;(curl -fsSL --proto &#039;=https&#039; --tlsv1.3 &quot;${IPV4_URL}&quot;)\n\nwhile IFS= read -r line; do\n    [[ -n &quot;$line&quot; ]] &amp;&amp; CF_IPS+=(&quot;${line}T&quot;)\ndone &lt; &amp;2\n    exit 1\nfi\n\nJOINED_IPS=$(IFS=', '; echo \"${CF_IPS[*]}\")\n\n# Create safety backup\ncp \"${CONF_FILE}\" \"${BACKUP_DIR}\/httpd_config.conf.${TIMESTAMP}\"\n\n# Verify or update useIpInProxyHeader directive\nif grep -q \"useIpInProxyHeader\" \"${CONF_FILE}\"; then\n    sed -i -E 's\/useIpInProxyHeader[[:space:]]+[0-9]+\/useIpInProxyHeader            2\/' \"${CONF_FILE}\"\nelse\n    echo \"useIpInProxyHeader            2\" &gt;&gt; \"${CONF_FILE}\"\nfi\n\necho \"Cloudflare IPs updated successfully. Validating LiteSpeed configuration syntax...\"\n\/usr\/local\/lsws\/bin\/lswsctrl test\n\necho \"Gracefully reloading LiteSpeed Web Server...\"\nsystemctl reload lsws || \/usr\/local\/lsws\/bin\/lswsctrl restart\necho \"LiteSpeed synchronized with Cloudflare Edge IPs.\"<\/code><\/pre>\n<p>Create a dedicated systemd service and timer to execute this synchronization weekly:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/systemd\/system\/cloudflare-lsws-sync.service\n[Unit]\nDescription=Synchronize Cloudflare IP Subnets to LiteSpeed Web Server\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nType=oneshot\nExecStart=\/usr\/local\/bin\/sync-cloudflare-lsws-ips.sh\n\n# \/etc\/systemd\/system\/cloudflare-lsws-sync.timer\n[Unit]\nDescription=Weekly Cloudflare IP Sync Timer for LiteSpeed\n\n[Timer]\nOnCalendar=Sun *-*-* 03:00:00\nRandomizedDelaySec=1800\nPersistent=true\n\n[Install]\nWantedBy=timers.target<\/code><\/pre>\n<p>Enable and start the timer using <code>systemctl enable --now cloudflare-lsws-sync.timer<\/code>.<\/p>\n<h3>Step 3: Optimized .htaccess Rules for Cache Separation<\/h3>\n<p>To eliminate cache collisions, enforce strict cache separation at the origin web server. Static assets (images, fonts, stylesheets, scripts) can be safely cached by Cloudflare edge nodes with aggressive TTLs. In contrast, HTML documents and dynamic API routes must instruct Cloudflare not to cache or to strictly validate origin cache state using LiteSpeed&#8217;s headers.<\/p>\n<p>Add these rules to your application&#8217;s root <code>.htaccess<\/code>:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># ====================================================================\n# Enterprise LiteSpeed + Cloudflare Cache Segregation Rules\n# ====================================================================\n\n    # Enable LSCache engine\n    CacheEngine on\n    CacheLookup on\n\n    # 1. Protect Dynamic &amp; E-Commerce Sessions\n    # Prevent upstream proxy caching when session cookies exist\n    RewriteEngine On\n    RewriteCond %{HTTP_COOKIE} (comment_author|wp-postpass|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|wp_woocommerce_session_) [NC]\n    RewriteRule .* - [E=Cache-Control:no-cache]\n\n    # 2. Enforce Proper Vary Headers for Edge Proxies\n    # Ensure proxies maintain distinct cache slots for mobile and authenticated users\n    Header append Vary \"User-Agent, Cookie, Accept-Encoding\" env=!dont-vary\n\n    # 3. Synchronize Cloudflare Cache Purging\n    # Allow LiteSpeed Cache plugin to communicate with Cloudflare API\n    # Ensure stale HTML is purged across Cloudflare edge when LSCache tag fires\n\n\n# Set Browser &amp; CDN Caching Policies for Static Assets\n\n    ExpiresActive On\n    ExpiresByType image\/webp \"access plus 1 year\"\n    ExpiresByType image\/avif \"access plus 1 year\"\n    ExpiresByType image\/jpeg \"access plus 1 year\"\n    ExpiresByType image\/png  \"access plus 1 year\"\n    ExpiresByType text\/css   \"access plus 1 month\"\n    ExpiresByType application\/javascript \"access plus 1 month\"\n    ExpiresByType font\/woff2 \"access plus 1 year\"\n<\/code><\/pre>\n<h3>Step 4: Linux Kernel Ingress Tuning for Reverse Proxy Traffic<\/h3>\n<p>Because all incoming traffic enters LiteSpeed from Cloudflare&#8217;s proxy clusters rather than individual consumer connections, the origin server experiences high TCP connection concentration from a smaller set of IP addresses. This requires tuning Linux kernel socket buffers, connection tracking tables, and TCP recycle heuristics.<\/p>\n<p>Deploy the following configuration in <code>\/etc\/sysctl.d\/99-lsws-cloudflare.conf<\/code>:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/sysctl.d\/99-lsws-cloudflare.conf\n# Kernel network optimizations for LiteSpeed Web Server behind Cloudflare\n\n# Increase system-wide file descriptors and socket backlog\nfs.file-max = 2097152\nnet.core.somaxconn = 65535\nnet.core.netdev_max_backlog = 16384\n\n# Scale TCP read\/write memory buffers (Min, Default, Max)\nnet.ipv4.tcp_rmem = 4096 87380 16777216\nnet.ipv4.tcp_wmem = 4096 65536 16777216\n\n# Enable TCP BBR congestion control and FQ queueing\nnet.core.default_qdisc = fq\nnet.ipv4.tcp_congestion_control = bbr\n\n# TCP connection reuse and quick termination handling\nnet.ipv4.tcp_tw_reuse = 1\nnet.ipv4.tcp_fin_timeout = 15\nnet.ipv4.tcp_keepalive_time = 300\nnet.ipv4.tcp_keepalive_probes = 5\nnet.ipv4.tcp_keepalive_intvl = 15\n\n# Expand conntrack table to prevent packet drops under heavy proxy volume\nnet.netfilter.nf_conntrack_max = 1048576\nnet.netfilter.nf_conntrack_tcp_timeout_established = 600<\/code><\/pre>\n<p>Apply the parameters immediately without rebooting by running <code>sysctl --system<\/code>.<\/p>\n<h2>Synchronizing Cloudflare Edge Purges with LiteSpeed Cache (LSCache)<\/h2>\n<p>To eliminate the delay between origin content modifications and edge updates, integrate LiteSpeed Cache with Cloudflare&#8217;s REST API. When an author updates a page or inventory item, LiteSpeed Cache automatically communicates with Cloudflare to purge the corresponding edge URL or Cache-Tag.<\/p>\n<ol>\n<li><strong>Generate Cloudflare API Token:<\/strong> In your Cloudflare dashboard, navigate to <em>My Profile &gt; API Tokens<\/em> and create a token with <code>Zone.Cache Purge<\/code> and <code>Zone.Zone Read<\/code> permissions scoped to your target domain.<\/li>\n<li><strong>Configure LSCache Cloudflare API Settings:<\/strong> In the WordPress administration dashboard, navigate to <em>LiteSpeed Cache &gt; Settings &gt; CDN &gt; Cloudflare API<\/em>. Enter your Cloudflare Account Email, API Token, and Zone ID.<\/li>\n<li><strong>Automated Cache Purge on Update:<\/strong> Enable <em>Auto Purge Cloudflare on Post Update<\/em>. LiteSpeed Cache will dispatch an asynchronous HTTPS POST request to Cloudflare&#8217;s purge endpoint every time a post is saved or an order changes, ensuring edge consistency within 150 milliseconds.<\/li>\n<\/ol>\n<p>For organizations operating enterprise web applications requiring guaranteed computing resources, low latency, and uncompromised uptime, building on <a href=\"https:\/\/merahost.org\">MeraHost Enterprise Cloud<\/a> delivers dedicated CPU threads, enterprise NVMe storage arrays, and pre-hardened LiteSpeed stacks designed to handle millions of daily requests with zero configuration friction.<\/p>\n<h2>Frequently Asked Questions (FAQs)<\/h2>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">Why does LiteSpeed report Cloudflare Anycast IPs instead of real visitor addresses?<\/summary>\n<p style=\"margin-top:10px;color:#444\">Cloudflare acts as a reverse proxy, terminating the TCP handshake with the visitor at its edge PoP and initiating a separate TCP session to your LiteSpeed origin. As a result, the source IP in the IP packet header received by LiteSpeed is Cloudflare&#8217;s egress interface. Without enabling <code>Use Client IP in Header: Trusted IP Only<\/code> and specifying Cloudflare&#8217;s trusted CIDR blocks in LiteSpeed, the server records the proxy IP in <code>REMOTE_ADDR<\/code>.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">Can Cloudflare and LiteSpeed Cache (LSCache) run simultaneously without conflicts?<\/summary>\n<p style=\"margin-top:10px;color:#444\">Yes, provided their caching responsibilities are properly segregated. Cloudflare should handle edge caching for static assets (images, CSS, JS, fonts) and geographical DDoS mitigation. LiteSpeed Cache should manage dynamic HTML, user sessions, shopping carts, and private fragments using shared memory. By connecting the LSCache plugin to the Cloudflare API, any origin purge event automatically flushes the corresponding edge URL or tag in real time.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">How do I verify that real IP restoration is functioning properly on my LiteSpeed origin?<\/summary>\n<p style=\"margin-top:10px;color:#444\">Create a temporary PHP verification script containing <code>&lt;?php echo \"REMOTE_ADDR: \" . $_SERVER['REMOTE_ADDR'] . \"<br \/>\nCF-Connecting-IP: \" . ($_SERVER['HTTP_CF_CONNECTING_IP'] ?? 'None');<\/code>. Access this script through your Cloudflare-proxied domain. If <code>REMOTE_ADDR<\/code> matches your actual public IP address (rather than a Cloudflare range starting with 172.64, 104.28, or 162.158), LiteSpeed&#8217;s trusted proxy unwrapping is functioning correctly. Delete the test script immediately after verification.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">How can I prevent attackers from bypassing Cloudflare and directly scanning my LiteSpeed origin?<\/summary>\n<p style=\"margin-top:10px;color:#444\">Use Linux iptables, nftables, or UFW to restrict inbound traffic on ports 80 and 443 exclusively to Cloudflare&#8217;s published IP ranges. Alternatively, configure Cloudflare Authenticated Origin Pulls (AOP) with a client TLS certificate installed in LiteSpeed&#8217;s SSL listener. This guarantees that any direct request sent to your origin IP address without a valid Cloudflare client certificate is dropped during the TLS handshake before reaching the web server layer.<\/p>\n<\/details>\n<div class=\"wp-block-group has-background\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:8px;padding:32px;margin:40px 0;text-align:center\">\n<h3 style=\"color:#001b41;margin-top:0;font-size:24px;font-weight:700\">Deploy Enterprise-Grade Production Infrastructure<\/h3>\n<p style=\"color:#444;font-size:16px;line-height:1.6;max-width:680px;margin:12px auto 24px auto\">Need guaranteed performance with zero price hikes? Host mission-critical workloads on <strong style=\"color:#001b41\">MeraHost<\/strong> with pure Enterprise NVMe, LiteSpeed Web Server, and Same Renewal Price, Always (starting at \u20b999\/mo).<\/p>\n<div class=\"wp-block-buttons\" style=\"display:flex;gap:16px;justify-content:center;flex-wrap:wrap\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"https:\/\/merahost.org\" style=\"background:#001b41;color:#ffffff;font-weight:700;padding:12px 28px;border-radius:4px;text-decoration:none;display:inline-block;font-size:15px\">Explore MeraHost NVMe Cloud &rarr;<\/a><\/div>\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link\" href=\"https:\/\/cpanelfree.com\" style=\"background:transparent;color:#001b41;font-weight:600;padding:12px 24px;border:2px solid #001b41;border-radius:4px;text-decoration:none;display:inline-block;font-size:15px\" rel=\"nofollow noopener\" target=\"_blank\">Deploy Free Staging on CpanelFree<\/a><\/div>\n<\/div>\n<\/div>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;1273&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;20&quot;,&quot;title&quot;:&quot;Configuring LiteSpeed Web Server with Cloudflare: Preventing Real IP Masking and Cache Collisions&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 20px; height: 20px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 16px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Master Cloudflare and LiteSpeed integration to restore real visitor IPs and eliminate cache collisions. Learn dual-tier caching strategies for peak NVMe throughput.<\/p>\n","protected":false},"author":1,"featured_media":1272,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135],"tags":[126,125,136,129,127],"class_list":["post-1273","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-optimization","tag-devops","tag-linux","tag-optimization","tag-performance","tag-sysadmin"],"_links":{"self":[{"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/posts\/1273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/comments?post=1273"}],"version-history":[{"count":0,"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/posts\/1273\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/media\/1272"}],"wp:attachment":[{"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/media?parent=1273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/categories?post=1273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/merahost.org\/blog\/wp-json\/wp\/v2\/tags?post=1273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}