[V2][CentOS] Get Cloudflare realip

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

Classic rpm install

a. System environment:

CentOS, via systemctl/service

b. Command:


c. Service/unit/compose file:


d. My complete Caddyfile or JSON config:

website.fr {
        root * /var/www/website.fr/prod
        encode zstd gzip

        log {

        output file /var/log/website.access.log
        format single_field common_log

        @cache {
                not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
                not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
                not method POST
                not expression {query} != ''

    route @cache {
        try_files /wp-content/cache/cache-enabler/{host}{uri}/https-index.html /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}

3. The problem I’m having:

I’m searching a way to get the realip behind cloudflare on my log file.

4. Error messages and/or full log output:

5. What I already tried:

I tried to build a specific caddy version with xcaddy but the realip cloudflare thing did not work.

6. Links to relevant resources:

Hi @BlackSheep,

Off the top of my head I don’t think there’s anything in native Caddy v2 to let you arbitrarily modify the common log field of the structured log output. You can do just about anything else, everywhere else, with just about any arbitrary data, but that log output is relatively static. If you used structured logs you could even pilfer Cloudflare’s header with the client’s IP directly.

But if you want that common log, you’d probably need something, either that realip thing or a custom log encoder or something along those lines.

I’m guessing GitHub - kirsch33/realip: realip module for Caddy v2 was the plugin you built with? Have you considered opening an issue on their repo to try troubleshoot realip cloudflare not working?

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.