How to properly use X-Forwarded-For in v2?

I'm having issues getting a x-forwarded-for IP address from Traefik. I have a Nextcloud instance setup but its reporting that my reverse proxy header is not configured right. I can see in v1 where "useXForwardedFor" was an option for the entrypoints. but I cannot figure out how that translates to v2s model. below is the relevant sections of my configuration files.

In this example, is a web server that responds to and, and is my nexcloud instance n I added the stsSeconds header and that cleared one alert i was having in Nextcloud, so I think I'm on the right track. My Traefik server is NOT behind another reverse proxy of any sort, its facing the public internet.

traefik.toml (Truncated):

    address = ":80"

    address = ":443"

        email = ""
        storage = "/root/acme.json"
                provider = "cloudflare"
                delayBeforeCheck = 0


                        entryPoints = ["web"]
                        middlewares = ["httpsredirect"]
                        rule = "HostRegexp(`{host:.+}`)"
                        service = "noop"
                        rule = "Host(``) || Host(``)"
                        service = "web"
                                certResolver = "foobar"
                        middlewares = ["headermods"]
                        rule = "Host(``)"
                        service = "data"
                                certResolver = "foobar"
                        scheme = "https"
                        stsSeconds = 15552000
                        hostsProxyHeaders = ["X-Forwarded-For"]
                                url = ""
                                url = ""
                                url = ""


in v1, useXForwardedFor is an option of the whitelisting system:

in v2, the whitelisting system is a middleware:

Note, in v1 the X-Forwarded-* headers are "trusted" by default, but in v2 they are not "trusted" by default, because it can be a security issue.

Ahh OK, i misunderstood what useXForwardedFor was used for then. My problem is I don't believe "x-forwarded-for" is being added to the headers from my Traefik install to my NextCloud install.

Any other ideas that i might be able to try?

What can of security issue could we have? Do you have any reference talking about this?

I have a PHP application managing security by IP by itself, but the security check is not working because the only IP it has is the Traefik one.

It looks like the only solution is to added trusted ip directly to the entrypoint, but my Traefik instance is not serving only this project.

EDIT: Nevermind. The header containing the real ip ARE currently transmitted to my PHP app, but it does not care because is not a trusted IP for my app.

See also:

This may help you @Rombus.