X-Forwarded-For ipwhitelist middleware

Hello, I’m new to Traefik and I’m having some difficulties with the ipwhitelist middleware.

I specified that my IP whitelist source range is my home IPv4 address, but the issue is that between me and the server with Traefik, there is an HAProxy. As a result, Traefik only sees the IP of the HAProxy for whitelisting.

I’ve added the x-forwarded-for header in my HAProxy configuration, but it doesn’t seem to help.

I also tried changing the IP strategy depth, but that didn’t work either.

Can you help me?

Thanks in advance.

FROM nginx:alpine

COPY index.html /usr/share/nginx/html/index.html

EXPOSE 80

LABEL traefik.enable=true
LABEL traefik.http.routers.web.rule="Host(`my.domain`) && PathPrefix(`/some/path`)"
LABEL traefik.http.services.web.loadbalancer.server.port=80

LABEL traefik.http.middlewares.ip-whitelist.ipwhitelist.sourcerange="MY_HOME_IPV4"

LABEL traefik.http.middlewares.strip-prefix.stripprefix.prefixes="/some/path"

LABEL traefik.http.routers.web.middlewares="ip-whitelist,strip-prefix"
CMD ["nginx", "-g", "daemon off;"]

# /etc/traefik/traefik.yml
entryPoints:
  web:
    address: ":80"
  websecure:
    address: ":443"

providers:
  docker:
    exposedByDefault: false

log:
  level: INFO

accessLog:
  fields:
    defaultMode: keep
    headers:
      defaultMode: keep

api:
  dashboard: true
  insecure: true
certificatesResolvers:
  http:
    acme:
      httpChallenge:
        entryPoint: web
      storage: /etc/traefik/acme.json

Hi Melvin,

welcome to the Traefik community.

Please mind that the IPWhiteList middleware ist deprecated in favour of the IPAllowList middleware.

I would guess that the ipStrategy.depth could solve this: Traefik HTTP Middlewares IPAllowList - Traefik