Control Panels

How to Use Cloudflare with cPanel & WHM: DNS, SSL, Real IPs and Caching

Enhance website speed, security, and reliability by integrating Cloudflare with cPanel & WHM.

Short answer: Add your domain to Cloudflare and change the nameservers. Proxy only the website records, and set mail, FTP and cPanel hostnames to DNS only. Keep AutoSSL on the server and set Cloudflare’s SSL mode to Full (strict). On the server, set up mod_remoteip so logs, cPHulk and your applications see real visitor IP addresses, and make sure your firewall never blocks Cloudflare’s IP ranges. Then add Cache Rules for static files, and for HTML only if you exclude logged-in, cart and admin pages.

What Cloudflare adds to a cPanel site

  • Faster static files: images, CSS and JavaScript are served from Cloudflare locations near your visitors.
  • Less load on the server: cached files no longer reach Apache or PHP.
  • Protection: DDoS protection, bot controls and firewall rules in front of the server.
  • Free certificates at the edge, in addition to the certificate on your server.

Cloudflare does not replace server security, updates or backups. It is a layer in front of the server.

Step 1: add the domain and check the DNS records

  1. Create a Cloudflare account and add your domain. Cloudflare imports the existing DNS records.
  2. Compare the imported records with the DNS zone in cPanel (Domains > Zone Editor). Add anything that is missing.
  3. Change the nameservers at your domain registrar to the two Cloudflare nameservers.
Record Proxy status Why
example.com and www Proxied (orange cloud) Website traffic goes through Cloudflare.
mail, MX targets DNS only (grey cloud) Cloudflare’s proxy carries web traffic only, so email must go straight to the server.
ftp DNS only FTP cannot pass through the proxy.
cpanel, webmail, whm DNS only Control panel ports such as 2083 and 2087 work most reliably directly.
The server hostname DNS only Used for SSL on services and for mail.

After the change, DNS is managed at Cloudflare, so future DNS changes must be made there, not in cPanel.

Step 2: set up SSL correctly

  1. Keep AutoSSL enabled on the server, so the site has a valid certificate. See our free SSL guide.
  2. In Cloudflare, open SSL/TLS > Overview and choose Full (strict).
  3. Turn on Always Use HTTPS in SSL/TLS > Edge Certificates.

Avoid Flexible mode:

Flexible sends traffic to your server over plain HTTP. If the site also redirects to HTTPS, visitors get an endless redirect loop, and data between Cloudflare and the server is not encrypted.

Step 3: restore real visitor IP addresses

Behind Cloudflare, every request seems to come from a Cloudflare IP address. That breaks access logs, cPHulk, login limits and the IP checks in your applications. Apache’s mod_remoteip fixes this.

  1. In WHM, open EasyApache 4, customise the current profile, and install mod_remoteip.
  2. Open Service Configuration > Apache Configuration > Include Editor and edit the Pre Main Include for all versions.
  3. Add the lines below, with every range from Cloudflare’s published lists at cloudflare.com/ips. The two ranges shown are only examples.
RemoteIPHeader CF-Connecting-IP
RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 103.21.244.0/22
# ...add every IPv4 and IPv6 range from cloudflare.com/ips-v4 and cloudflare.com/ips-v6

Save and restart Apache. Cloudflare adds ranges from time to time, so check the list every few months.

Step 4: keep the firewall from blocking Cloudflare

If your firewall blocks a Cloudflare IP address, every visitor routed through that Cloudflare location loses access. Add Cloudflare’s ranges to the allow list. With CSF, add each range to /etc/csf/csf.allow and run csf -r. See our CSF firewall guide. Block abusive visitors in Cloudflare’s security rules instead, where the real IP address is known.

Step 5: set up caching

By default, Cloudflare caches static files such as images, CSS and JavaScript, but not HTML pages. That default is safe for every site. To cache HTML as well, create a Cache Rule in Caching > Cache Rules:

  • Set cache eligibility to Eligible for cache for your public pages.
  • Add a separate rule that bypasses the cache for /wp-admin, /wp-login.php, /cart, /checkout, /my-account, and any request with a login or cart cookie.
  • Set an Edge TTL, for example a few hours, so updates appear without manual purges.

Test while logged in and logged out, and place a test order on stores, before you rely on HTML caching. Purge the cache in Caching > Configuration after large changes.

Step 6: security settings worth turning on

  • ✓ The free managed WAF rules in Security, plus the full managed rulesets on paid plans.
  • ✓ Bot Fight Mode, if bots load your site. Test it, because it can block legitimate tools and API clients.
  • ✓ A rate limiting rule for /wp-login.php or other login pages.
  • ✓ Under Attack Mode only during an attack. It adds a browser check for every visitor.

Troubleshooting

Error Meaning Fix
Too many redirects SSL mode is Flexible while the site forces HTTPS Switch to Full (strict).
521 The server refused the connection Check that Apache is running and that the firewall allows Cloudflare.
522 The connection to the server timed out Check server load and the firewall, and that the DNS record points to the right IP address.
525 or 526 SSL problem between Cloudflare and the server Check that AutoSSL issued a valid certificate for the domain.
Email stopped working Mail records are proxied Set mail and MX records to DNS only.

Need help with this?

Want Cloudflare set up correctly on your cPanel server? Our team can configure DNS, SSL, real IPs and caching for you.

See server management plansContact @CustomerPanel

Frequently asked questions

Does Cloudflare work with cPanel AutoSSL?

Yes. Keep AutoSSL on the server and use the Full (strict) SSL mode in Cloudflare.

Should cPanel and webmail be proxied through Cloudflare?

No. Set cpanel, webmail, whm, mail and ftp records to DNS only, so those services connect straight to the server.

Why do my logs show Cloudflare IP addresses?

Apache sees Cloudflare as the visitor. Install mod_remoteip and trust Cloudflare’s IP ranges, as shown in Step 3.

Can Cloudflare cache my WordPress pages?

Yes, with a Cache Rule, as long as you bypass the cache for logged-in users, the admin area and cart or checkout pages.

Is the free Cloudflare plan enough?

For most small sites, yes. Paid plans add more WAF rules, image optimisation and other features.


Sources