Server & 3rd-party tools

CloudFlare

Settings that break streaming, and the ones that help

CloudFlare is a popular content delivery network (CDN) and security service that provides a range of features to enhance website performance and security. However, when your RKHM is installed on a domain proxied through CloudFlare, certain issues can arise:

  1. Real IP Address Not Passed: By default, CloudFlare masks the real IP addresses of users, passing CloudFlare IPs instead. This can break functionalities in your RKHM that rely on users' real IP addresses.
  2. Page and Endpoint Caching: if you add Cloudflare cache rules for pages, API endpoints or protected media, visitors can receive someone else's cached response. Keep caching to static files (Cloudflare's default) — see the recommended settings below.

With Cloudflare support turned on, RKHM reads each visitor's real IP address from Cloudflare's CF-Connecting-IP header — but only for requests that really arrive from Cloudflare's network, so nobody can fake an address by going around Cloudflare. Real addresses matter for the firewall, session IP locks, IP geolocation, HLS keys and download links. (Cloudflare support was added in v2.0.59.)

Enabling CloudFlare Support

Follow the steps below to enable CloudFlare support in RKHM:

1. Locate the Configuration File: Navigate to the ~rkhm/api/app/ directory

2. Edit the User Configuration File: Open config_user.php in a text editor.

3. Modify the CloudFlare Cache Setting: 

Find the line:

define( "cf_cache", false ); 

Change it to:

define( "cf_cache", true );

Save and Close the File

4. Clear CloudFlare Cache:

It may be beneficial to clear CloudFlare’s cache to ensure the new settings take immediate effect. This can be done through the CloudFlare dashboard by navigating to the Caching section and selecting the "Purge Everything" option.

  • Don't add cache rules for /api/, /admin/, /files/protected/, /files/hls_keys/, protector.php or hls_key.php. Cloudflare's default (static files only) is what RKHM expects.
  • Cloudflare's Free and Pro plans reject uploads larger than 100 MB in a single request. If you or your users upload larger files, turn on Setting → Files → Upload Setting → Chunk upload and set the chunk size below 100 MB.
  • After changing these settings, use Purge Everything once so no old copies are left.

Older versions

If you are upgrading from a release before 2.0.59 and the admin IP lock prevents login behind Cloudflare, you may need to temporarily set admin_ip_lock to false in config_user.php. Restore it after updating and enabling Cloudflare support.

define( "admin_ip_lock", true ); 

And change it to:

define( "admin_ip_lock", false ); 

You can revert this change after updating to v2.0.59