Apache CF RealIP

April 4, 2026 · View on GitHub

License

Apache CF RealIP

An Apache httpd module that automatically fetches Cloudflare IPv4 and IPv6 CIDR ranges and generates RemoteIPTrustedProxy configuration for mod_remoteip. Port of nginx-cf-realip for Apache.

Implementation: Rust core with thin C FFI shim for Apache module registration.

Features

  • Automatic Cloudflare IP fetching — downloads authoritative IPv4/IPv6 CIDR lists
  • HTTPS with TLS verification — secure fetching with certificate validation
  • SHA256 change detection — only rewrites config when IPs actually change
  • Periodic refresh — configurable update interval (minimum 5 minutes)
  • Atomic file writes — no partial/corrupt config files
  • Integrates with mod_remoteip — generates RemoteIPTrustedProxy directives
  • Memory safe — Rust core prevents buffer overflows and use-after-free

Quick Start

1. Install

Debian/Ubuntu:

# Add the OBS repository (see Installation Guide for details)
apt install apache-cf-realip

2. Configure Apache

LoadModule cf_realip_module modules/mod_cf_realip.so
LoadModule remoteip_module modules/mod_remoteip.so

# Cloudflare IP list settings
CfRemoteipEnabled on
CfRemoteipRefreshInterval 3600
CfRemoteipOutputPath /etc/apache2/conf-available/cf-trusted-proxies.conf

# Include the generated trusted proxy list
Include /etc/apache2/conf-available/cf-trusted-proxies.conf

RemoteIPHeader CF-Connecting-IP

3. Verify

apachectl configtest && apachectl graceful

Configuration Reference

DirectiveContextDefaultDescription
CfRemoteipEnabledserver configoffEnable/disable Cloudflare IP fetching
CfRemoteipSourceUrlserver configCloudflare officialIPv4 list URL
CfRemoteipSourceUrlV6server configCloudflare officialIPv6 list URL
CfRemoteipRefreshIntervalserver config3600Refresh interval in seconds (min: 300)
CfRemoteipOutputPathserver configWhere to write the generated config

Building from Source

# Build Rust library
cargo build --release

# Build and install Apache module
make
sudo make install
ModuleDescriptionGitHub
apache-goneReturn HTTP 410 Gone for permanently removed URIsGitHub
apache-torblockerControl access from Tor exit nodesGitHub
apache-wafIP/CIDR-based access control with named listsGitHub

nginx Counterpart

nginx ModuleApache Module
nginx-cf-realipapache-cf-realip (this project)

License

Apache License 2.0. See LICENSE.md.