Sign in

Mod for swag

Cloudflare real IP

Writes Cloudflare's edge IP ranges to /config/nginx/cf_real-ip.conf as set_real_ip_from directives at startup, so nginx sees the visitor's real IP behind Cloudflare.

arch
amd64, arm64
built

Use it#

Set DOCKER_MODS on the swag container and recreate it. The mod is pulled on every start; several mods are separated with |.

DOCKER_MODS=ghcr.io/linuxserver-playground/mods:swag-cloudflare-real-ip

:swag-cloudflare-real-ip always gets the newest build. To stay on this one, pin its tag:

DOCKER_MODS=ghcr.io/linuxserver-playground/mods:swag-cloudflare-real-ip-838e10d
services:
  swag:
    image: ghcr.io/linuxserver-playground/swag:latest
    environment:
      - DOCKER_MODS=ghcr.io/linuxserver-playground/mods:swag-cloudflare-real-ip

Details#

At startup the mod reads Cloudflare’s IPv4 and IPv6 ranges from the Cloudflare API (the published lists are https://www.cloudflare.com/ips-v4 and https://www.cloudflare.com/ips-v6), adds the container’s own interface networks, and writes one set_real_ip_from line per range to /config/nginx/cf_real-ip.conf in your persistent data.

To enable nginx to read the IPs from this file, you need the following in your nginx.conf (http section):

real_ip_header X-Forwarded-For;
real_ip_recursive on;
include /config/nginx/cf_real-ip.conf;

You may need to add this mod (and the above config changes) to every nginx based container being proxied by SWAG.

Cloudflare tunnels

In case you use Cloudflare tunnels, the real IP might be reported in containers as 127.0.0.1. In this case, add set_real_ip_from 127.0.0.1; after the include in the http section of nginx.conf:

real_ip_header X-Forwarded-For;
real_ip_recursive on;
include /config/nginx/cf_real-ip.conf;
set_real_ip_from 127.0.0.1;

Community project

Improve this mod, or make your own

Mods are how LinuxServer images grow without getting heavier: a Dockerfile, a few scripts and a mod.yml. If this one is missing something, or you need one like it for another image, an AI agent in our harness can build and test it with you.

Ask your agent

  • The swag-cloudflare-real-ip mod <what is wrong>. Fix it, test it and draft the PR.
  • Make a mod like swag-cloudflare-real-ip for <another image>, and test it.

Making a mod Every way to help Get the harness (opens in a new tab)

Source: swag-cloudflare-real-ip branch (opens in a new tab). Every mod