{
    "title": "Cloudflare in front of WordPress: real IP, WAF and mistakes to avoid",
    "seo_title": "Cloudflare and WordPress: real visitor IP and WAF rules",
    "h1": "Cloudflare in front of WordPress: real IP, WAF and mistakes to avoid",
    "description": "Behind Cloudflare, WordPress sees the wrong IPs. Restore CF-Connecting-IP safely, protect the origin and write useful WAF rules.",
    "lead": "Restore visitors' real IP address behind Cloudflare without opening the door to spoofing, close direct access to the origin and write useful firewall rules for WordPress.",
    "language": "en",
    "locale": "en-US",
    "type": "article",
    "url": "https://www.wp-feint.com/cloudflare-wordpress-real-visitor-ip/",
    "canonical": "https://www.wp-feint.com/cloudflare-wordpress-real-visitor-ip/",
    "markdown": "https://www.wp-feint.com/cloudflare-wordpress-real-visitor-ip/index.md",
    "json": "https://www.wp-feint.com/cloudflare-wordpress-real-visitor-ip/index.json",
    "published": "2026-10-03T07:00:00+00:00",
    "modified": "2026-11-22T14:33:27+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "Cloudflare in front of WordPress: real IP, WAF and mistakes to avoid",
            "url": "https://www.wp-feint.com/cloudflare-wordpress-real-visitor-ip/",
            "markdown": "https://www.wp-feint.com/cloudflare-wordpress-real-visitor-ip/index.md",
            "json": "https://www.wp-feint.com/cloudflare-wordpress-real-visitor-ip/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Cloudflare devant WordPress : vraie IP, WAF et erreurs à éviter",
            "url": "https://www.wp-feint.com/fr/cloudflare-wordpress-vraie-ip/",
            "markdown": "https://www.wp-feint.com/fr/cloudflare-wordpress-vraie-ip/index.md",
            "json": "https://www.wp-feint.com/fr/cloudflare-wordpress-vraie-ip/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Cloudflare delante de WordPress: IP real, WAF y errores que evitar",
            "url": "https://www.wp-feint.com/es/cloudflare-wordpress-ip-real/",
            "markdown": "https://www.wp-feint.com/es/cloudflare-wordpress-ip-real/index.md",
            "json": "https://www.wp-feint.com/es/cloudflare-wordpress-ip-real/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "Cloudflare vor WordPress: echte IP, WAF und Fehler, die du vermeiden solltest",
            "url": "https://www.wp-feint.com/de/cloudflare-wordpress-echte-ip/",
            "markdown": "https://www.wp-feint.com/de/cloudflare-wordpress-echte-ip/index.md",
            "json": "https://www.wp-feint.com/de/cloudflare-wordpress-echte-ip/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "Cloudflare davanti a WordPress: vero IP, WAF ed errori da evitare",
            "url": "https://www.wp-feint.com/it/cloudflare-wordpress-vero-ip/",
            "markdown": "https://www.wp-feint.com/it/cloudflare-wordpress-vero-ip/index.md",
            "json": "https://www.wp-feint.com/it/cloudflare-wordpress-vero-ip/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Cloudflare na frente do WordPress: IP real, WAF e erros a evitar",
            "url": "https://www.wp-feint.com/pt/cloudflare-wordpress-ip-real-waf/",
            "markdown": "https://www.wp-feint.com/pt/cloudflare-wordpress-ip-real-waf/index.md",
            "json": "https://www.wp-feint.com/pt/cloudflare-wordpress-ip-real-waf/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Cloudflare voor WordPress: echt IP-adres, WAF en fouten om te vermijden",
            "url": "https://www.wp-feint.com/nl/cloudflare-wordpress-echt-ip-adres/",
            "markdown": "https://www.wp-feint.com/nl/cloudflare-wordpress-echt-ip-adres/index.md",
            "json": "https://www.wp-feint.com/nl/cloudflare-wordpress-echt-ip-adres/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "Cloudflare in front of WordPress: real IP, WAF and mistakes to avoid"
        },
        {
            "level": 2,
            "text": "Why WordPress sees Cloudflare's address"
        },
        {
            "level": 2,
            "text": "The headers Cloudflare passes along"
        },
        {
            "level": 2,
            "text": "The trap: a header can be forged in one line"
        },
        {
            "level": 2,
            "text": "Restoring the real IP at the server level"
        },
        {
            "level": 3,
            "text": "Apache: mod_remoteip"
        },
        {
            "level": 3,
            "text": "Nginx: ngx_http_realip_module"
        },
        {
            "level": 3,
            "text": "LiteSpeed and shared hosting"
        },
        {
            "level": 2,
            "text": "Closing direct access to the origin"
        },
        {
            "level": 2,
            "text": "Useful firewall rules for WordPress"
        },
        {
            "level": 2,
            "text": "Common mistakes"
        },
        {
            "level": 2,
            "text": "WP Feint behind Cloudflare"
        },
        {
            "level": 3,
            "text": "Key takeaways"
        },
        {
            "level": 2,
            "text": "Sources"
        }
    ],
    "body": "Putting Cloudflare in front of a WordPress site gives you caching, a firewall and protection against denial-of-service attacks. But WordPress no longer sees your visitors: it sees Cloudflare's servers. Handled badly, this detail disables login attempt limiting or lets an attacker pick their own IP address. Here is how to restore the real IP in the right place, protect the origin, and write a few useful firewall rules.\n\n## Why WordPress sees Cloudflare's address\n\nCloudflare works as a reverse proxy: the visitor connects to Cloudflare, then Cloudflare opens its own connection to your server. For PHP, the `$_SERVER['REMOTE_ADDR']` variable therefore holds the address of the Cloudflare node. As long as nothing is fixed:\n\n- **login attempt limiting** counts the failures of thousands of visitors against a handful of Cloudflare addresses, and ends up either blocking innocent people or blocking nothing at all;\n- the **logs** of the server and of security plugins become useless during an incident;\n- comment antispam tools and a store's anti-fraud checks lose their main clue.\n\n![Diagram of a request's path from the visitor to Cloudflare and then to the origin server, showing the value of REMOTE_ADDR before and after the address is restored](https://www.wp-feint.com/media/chemin-requete-cloudflare-en.webp)\n\n## The headers Cloudflare passes along\n\n| Header | Content | Availability |\n| --- | --- | --- |\n| `CF-Connecting-IP` | A single address: that of the client connected to Cloudflare | All plans |\n| `True-Client-IP` | Same value, under the name used by other CDNs | Enterprise plan, via a managed transform |\n| `X-Forwarded-For` | A list: if the request already contained one, Cloudflare appends the address that connected | All plans |\n| `CF-IPCountry` | Two-letter country code (`XX` unknown, `T1` Tor network) | Via the managed transform for visitor location headers |\n| `CF-Ray` | Request identifier, useful for support | All plans |\n\n*Cloudflare recommends reading CF-Connecting-IP or True-Client-IP, which contain only one address.*\n\n`X-Forwarded-For` is the most misleading: its first value may have been written by the client itself. A plugin that takes its first element will believe any made-up address.\n\n## The trap: a header can be forged in one line\n\nAn HTTP header is just text sent by the client. If your server also answers directly, without going through Cloudflare, an attacker can call it with `CF-Connecting-IP` set to whatever they like. The [Apache](https://www.wp-feint.com/glossary/apache-http-server/) documentation makes the point for `mod_remoteip`: it is trivial for a client to impersonate another, so you should only trust known intermediate proxies.\n\n![Decision tree: a request reaches the origin with a CF-Connecting-IP header; the header is accepted only if the connection comes from a Cloudflare IP range](https://www.wp-feint.com/media/usurpation-en-tete-en.webp)\n\nThe consequences of blind trust are concrete: the attacker changes address on every password attempt and gets around the limiting, gets a legitimate customer's address banned, or muddies your logs.\n\n## Restoring the real IP at the server level\n\nThe right place is the web server, before PHP: WordPress and every plugin then receive the correct value in `REMOTE_ADDR`, with no per-plugin configuration. Cloudflare publishes its IP ranges as plain text at `https://www.cloudflare.com/ips-v4/` and `https://www.cloudflare.com/ips-v6/`, and through its API at `https://api.cloudflare.com/client/v4/ips`. As of October 2026, the list contains 15 IPv4 ranges and 7 IPv6 ranges. It rarely changes, but it does change: automate the update rather than copying it once and for all.\n\n### Apache: mod_remoteip\n\nEnable the module (`a2enmod remoteip` on Debian and Ubuntu), then declare each range. `RemoteIPTrustedProxy` restricts trust to the listed addresses: without a directive of this kind, the module trusts any host that sends the header.\n\n```\nRemoteIPHeader CF-Connecting-IP\nRemoteIPTrustedProxy 173.245.48.0/20\nRemoteIPTrustedProxy 103.21.244.0/22\n# ... one line per IPv4 and IPv6 range published by Cloudflare\nRemoteIPTrustedProxy 2400:cb00::/32\n\n# Logs: %a (restored address) instead of %h\nLogFormat \"%a %l %u %t \\\"%r\\\" %>s %O \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" combined\n```\n\n### Nginx: ngx_http_realip_module\n\nThe module is not compiled into [Nginx](https://www.wp-feint.com/glossary/nginx/) by default (`--with-http_realip_module` option); check that it is present with `nginx -V`. `set_real_ip_from` defines the trusted addresses.\n\n```\nset_real_ip_from 173.245.48.0/20;\nset_real_ip_from 103.21.244.0/22;\n# ... one line per range published by Cloudflare\nset_real_ip_from 2400:cb00::/32;\nreal_ip_header CF-Connecting-IP;\n```\n\n### LiteSpeed and shared hosting\n\nOn [LiteSpeed](https://www.wp-feint.com/glossary/litespeed/), Cloudflare states that the **Use Client IP in Header** option makes the client's address appear in `REMOTE_ADDR`. On shared hosting without access to the configuration, ask your host whether it already restores the address for Cloudflare. Be wary of PHP snippets that copy `HTTP_CF_CONNECTING_IP` into `REMOTE_ADDR` without checking the originating address: they create exactly the flaw described above.\n\nTo check: log in from a private browsing window, then compare the address recorded by the server or by your security plugin with your public address.\n\n## Closing direct access to the origin\n\nRestoring the IP is not enough if the origin can still be reached directly: the attacker then bypasses Cloudflare's firewall. Cloudflare's documentation compares several methods:\n\n| Method | Security level according to Cloudflare | Plans | Note |\n| --- | --- | --- | --- |\n| Cloudflare Tunnel (`cloudflared`) | Most secure | All | The origin no longer has a public address to attack |\n| Authenticated Origin Pulls | Very secure | All | Full or Full (strict) SSL mode required; a custom certificate is recommended |\n| Allowlisting Cloudflare IPs | Moderate | All | Ranges must be kept up to date; combine with another measure |\n| Secret header checked by the origin | Moderate | All | Vulnerable to replay if the secret leaks |\n\nThink about history too: if your server's address was public before Cloudflare, DNS history services have kept it. Cloudflare advises proxying all relevant DNS records and, if possible, changing the origin's address.\n\n*Video in French: a demonstration of bypassing a firewall like Cloudflare's by attacking the origin server directly.*\n\n## Useful firewall rules for WordPress\n\nCloudflare's firewall does not offer the same tools on every plan. Before writing rules, check what you have available:\n\n| Feature | Free | Pro | Business | Enterprise |\n| --- | --- | --- | --- | --- |\n| Custom rules | 5 | 20 | 100 | 1,000 |\n| Regular expressions | No | No | Yes | Yes |\n| Free managed ruleset | Yes | Yes | Yes | Yes |\n| Cloudflare Managed Ruleset and OWASP Core Ruleset | No | Yes | Yes | Yes |\n| Rate limiting rules | 1 (per IP, 10 s period) | Depends on plan | Depends on plan | Depends on plan |\n\n*Based on Cloudflare's WAF documentation.*\n\nWith five free rules, prioritize those that target the most common attacks on WordPress. Example expressions to enter in the rule editor:\n\n```\n# 1. Block XML-RPC if you don't use it (Jetpack and some apps need it)\n(http.request.uri.path eq \"/xmlrpc.php\")\n\n# 2. Managed challenge on login for countries where you have no users\n(http.request.uri.path eq \"/wp-login.php\" and ip.src.country ne \"FR\")\n\n# 3. Block PHP execution in media uploads\n(http.request.uri.path contains \"/wp-content/uploads/\" and http.request.uri.path contains \".php\")\n```\n\n- Use the **Managed Challenge** action rather than blocking on the login page: a human gets through, a script usually fails.\n- Do not challenge all of `/wp-admin/`: `admin-ajax.php` is also used by visitors (forms, carts, filters).\n- The `ip.src.country` field replaces `ip.geoip.country`, which is deprecated.\n- A country rule gets in the way of administrators who travel: plan an exception by address or access through a VPN.\n\n## Common mistakes\n\n| Mistake | Symptom | Fix |\n| --- | --- | --- |\n| \"Flexible\" SSL/TLS mode with an HTTPS redirect on the origin | Infinite redirect loop | Switch to Full or Full (strict), which Cloudflare recommends |\n| Reading the first value of `X-Forwarded-For` | Made-up addresses in the logs | Read `CF-Connecting-IP`, restored by the server |\n| Forgotten IPv6 ranges | Some visitors keep a Cloudflare address | Declare both IPv4 and IPv6 ranges |\n| Origin reachable directly | Firewall bypassed, headers forgeable | Tunnel, Authenticated Origin Pulls or allowlist |\n| \"Cache everything\" rule with no exceptions | Login or account pages served to other visitors | Exclude `/wp-admin/`, `wp-login.php`, cart, account and logged-in visitors |\n\nBy default, Cloudflare caches neither HTML nor responses that contain a `Set-Cookie` header. The risk comes from rules that force pages to be cached: that is where you need to plan exclusions.\n\n*Tutorial in French: connecting a WordPress site to Cloudflare and configuring the official plugin.*\n\n## WP Feint behind Cloudflare\n\nWP Feint Pro deliberately ignores the `X-Forwarded-For` header received from the client, to prevent the spoofing described above. Its Cloudflare support reads `CF-Connecting-IP` only when the request comes from an official Cloudflare IP range, updated weekly; [login limiting](https://www.wp-feint.com/features/login-attempt-limiting/), bans and logs then see the visitor's real address. If your server already restores the address (mod_remoteip, Nginx real_ip), even better, and this option can stay off. The counters use an HMAC fingerprint of the address, never the address in clear text. Host-specific settings are detailed on the [host and cache compatibility](https://www.wp-feint.com/features/hosting-and-cache-compatibility/) page.\n\n### Key takeaways\n\n- Behind Cloudflare, `REMOTE_ADDR` holds Cloudflare's address until the server restores the real one.\n- Restore it at the server level (mod_remoteip, realip, LiteSpeed option) using `CF-Connecting-IP` and only the ranges published by Cloudflare, IPv6 included.\n- Never trust an address header without checking where the connection comes from.\n- Close direct access to the origin: Tunnel, Authenticated Origin Pulls or allowlist.\n- On the free plan, five custom rules are enough for XML-RPC, the login page and PHP in media uploads.\n- Avoid Flexible SSL mode and cache rules without exclusions.\n\n## Sources\n\n- [Cloudflare: Cloudflare HTTP headers](https://developers.cloudflare.com/fundamentals/reference/http-headers/)\n- [Cloudflare: Restoring original visitor IPs](https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/)\n- [Apache HTTP Server: mod_remoteip](https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html)\n- [Nginx: ngx_http_realip_module](https://nginx.org/en/docs/http/ngx_http_realip_module.html)\n\nOther sources consulted: official documentation and official vendor pages.",
    "categories": [
        "Hosting and server"
    ],
    "format": "application/json"
}