Middleware does not exist with nextcloud

Hi, I have an error I have also read a couple of times here but I have a feeling its never exactly the setup I run so I'm already sorry for creating another one :confused:

The setup is I run portainer and have a docker compose file of traefik+nextcloud+mariadb and nextcloud has its super fancy gui telling one issues right now one issue is about well-known redirects to webdav caldav etc and from what I have read and also found out with gpt is I need middlewares for that but somehow even though they are in my traefik.yml I get does not exist and nothing works when I try to incorporate them.

# Enable access logs
accessLog:
  filePath: "/logs/traefik_access.log"
  format: json
  bufferingSize: 0
  fields:
    headers:
      defaultMode: drop
      names:
        User-Agent: keep  # Keep the User-Agent in logs

# Enable detailed logging for Traefik
log:
  level: DEBUG
  filePath: "/logs/traefik.log"
  format: json

# Define entry points (ports)
entryPoints:
  web:
    address: ":80"
  websecure:
    address: ":443"
  traefik:
    address: ":8080"  # Dashboard port

# Define providers
providers:
  docker:
    exposedByDefault: false  # Only expose containers explicitly

# Configure Let's Encrypt for HTTPS
certificatesResolvers:
  myresolver:
    acme:
      email: "myemail@123.com"  # Your email for notifications
      storage: "/letsencrypt/acme.json"  # Store certificates here
      tlsChallenge: true  # Use TLS challenge

http:
  middlewares:
    nextcloud-dav:
      redirectRegex:
        regex: "^/.well-known/(caldav|carddav)"
        replacement: "/remote.php/dav/"
        permanent: true

    redirect-to-https:
      redirectScheme:
        scheme: https
        permanent: true

and

services:
  traefik:
    image: traefik:v2.9
    command:
      - "--configFile=/traefik.yml"  # Use the updated traefik.yml file
    ports:
      - "80:80"  # HTTP for Let's Encrypt challenge
      - "443:443"  # HTTPS required by Let's Encrypt
      - "65386:443"  # Custom HTTPS port for external access (after certificate is issued)
      - "65385:8080"  # Map the new entry point for the dashboard
    dns:
      - 8.8.8.8
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"  # Allows Traefik to access Docker
      - "./letsencrypt:/letsencrypt"  # Folder to store the Let's Encrypt data (certificate, keys, etc.)
      - "/mnt/dietpi_userdata/docker-data/volumes/traefik/traefik.yml:/traefik.yml"  # Host to container volume mapping
      - "/mnt/dietpi_userdata/docker-data/volumes/traefik_logs:/logs"  # Host directory for logs
    networks:
      - nextcloud-net

[...]

  nextcloud:
    image: nextcloud:latest
    restart: unless-stopped
    environment:
[...]
    dns:
      - 8.8.8.8
    volumes:
      - /mnt/dietpi_userdata/docker-data/volumes/nextcloud_traefik:/var/www/html/
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nextcloud.rule=Host(`fancyhost.net`)"
      - "traefik.http.routers.nextcloud.entrypoints=websecure"
      - "traefik.http.services.nextcloud.loadbalancer.server.port=80"
      - "traefik.http.routers.nextcloud.tls=true"
      - "traefik.http.routers.nextcloud.tls.certresolver=myresolver"  # Use the resolver defined in Traefik
      - "traefik.http.routers.nextcloud.middlewares=file:nextcloud-dav"  # Correct reference
      - "traefik.http.routers.nextcloud-http.entrypoints=web"
      - "traefik.http.routers.nextcloud-http.rule=Host(`fancy.host.net`)"
      - "traefik.http.routers.nextcloud-http.middlewares=file:redirect-to-https"  # Correct reference
    networks:
      - nextcloud-net

Seriously? You get multiple error messages, but you are not able to copy&paste them here?

Traefik is currently at v2.11 or v3.1, please upgrade for bugfixes and improved security.

And this is a chatbot hallucination, maybe use the search function of this forum (maybe with "nextcloud"), instead of a chatbot:

traefik.http.routers.nextcloud.middlewares=file:nextcloud-dav