StripPrefix does not work if middleware compress=true?

Hi there,

I didn't find any answer yet, so I post this issue here. My problem is that for some reason, the stripprefix middleware does not work, when I set the compress middleware to true. Here the prefix /test remains, as if the command was ignored.

It's the same with the replacepath middleware. Here the entire path remains.

As soon as compress is set to false, both, stripprefix and replacepath work as expected.

This is my docker compose, which just provides a simple webserver:

version: '2'

networks:
  traefik:
    name: traefik
    external: true

services:
  simple-webserver:
    image: python:3.9.18-slim
    volumes:
      - ./data:/web
    working_dir: /web
    command: bash -c "python3 -m http.server 8080"
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.simple-webserver.rule=Host(`thisismyexampleurl.com`)"
      - "traefik.http.routers.simple-webserver.rule=PathPrefix(`/test/`)"
      - "traefik.http.middlewares.simple-webserver-pathstrip.stripprefix.prefixes=/test"
      - "traefik.http.routers.simple-webserver.middlewares=simple-webserver-pathstrip"
#      - "traefik.http.middlewares.test-replacepath.replacepath.path=/"
#      - "traefik.http.routers.simple-webserver.middlewares=test-replacepath"
      - "traefik.http.routers.simple-webserver.service=simple-webserver"
      - "traefik.http.routers.simple-webserver.entrypoints=websecure"
      - "traefik.http.routers.simple-webserver.tls=true"
      - "traefik.http.routers.simple-webserver.tls.certresolver=letsencrypt"
      - "traefik.http.services.simple-webserver.loadbalancer.server.port=8080"
      - "traefik.http.routers.simple-webserver.middlewares=compresstraefik"
      - "traefik.http.middlewares.compresstraefik.compress=true"
      - "traefik.docker.network=traefik"

Make sure to not overwrite the middlewares assignment, it should be a single assignement with comma separation:

.middlewares=compresstraefik,test-replacepath

Not sure if the order matters, you probably need to test.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.