time="2023-07-17T12:08:57+01:00" level=debug msg="mime: no media type" middlewareName=compress-with-gzip@docker middlewareType=Compress
docker-compose.yml
volumes:
traefik:
services:
traefik:
image: traefik:v2.10.1
container_name: traefik
restart: unless-stopped
security_opt: [ 'no-new-privileges:true' ]
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./dynamic-config/:/etc/traefik/dynamic-config/:ro
- traefik:/data/
ports:
- 80:80
- 443:443
healthcheck:
start_period: 10s
interval: 30s
timeout: 10s
retries: 3
test: traefik healthcheck --ping
environment:
- LEGO_DISABLE_CNAME_SUPPORT=true
command:
- --providers.docker=true
- --providers.docker.exposedByDefault=false
- --providers.docker.watch=true
- --providers.file.directory=/etc/traefik/dynamic-config/
- --providers.file.watch=true
#- --certificatesresolvers.myresolver ...
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --entrypoints.websecure.http.tls=true
- --entrypoints.websecure.http.tls.options=default
- --entrypoints.websecure.http.middlewares=secure-headers@file,compress-with-gzip@docker
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.permanent=true
- --entrypoints.websecure.http.tls.certResolver=myresolver
- --entrypoints.websecure.http.tls.domains[0].main=${DOMAIN}
- --entrypoints.websecure.http.tls.domains[0].sans=*.${DOMAIN}
- --api=true
- --ping=true
labels:
traefik.enable: true
traefik.http.middlewares.redirect-naked-to-www.redirectregex.regex: ^https?://(?:www\\.)?(.+)
traefik.http.middlewares.redirect-naked-to-www.redirectregex.replacement: https://www.$${1}
traefik.http.middlewares.redirect-naked-to-www.redirectregex.permanent: true
traefik.http.middlewares.compress-with-gzip.compress: true
./dynamic-config/security.yml
tls:
options:
default:
sniStrict: true
minVersion: VersionTLS12
cipherSuites:
- TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
- TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305
http:
middlewares:
secure-headers:
headers:
customFrameOptionsValue: DENY
contentTypeNosniff: true
referrerPolicy: strict-origin-when-cross-origin
stsSeconds: 0
What did you see instead?
The logs shown above.
What version of Traefik are you using?
v2.10.1
What is your environment & configuration?
docker
debian
If applicable, please paste the log output in DEBUG level
See above.
There are no errors at all other than that - and everything works, except for that error message.
Also, the first logs (above) complain about unknown middleware, but when I enable debug logging, the second logs (above) complain about MIME types. That's weird because:
there's a connection between mime type and compression
it doesn't show the info AND debug logs, only the debug logs (I expected it would show both)
...so maybe the core issue is MIME types? But for all apps?
Hello,
When you define --entrypoints.websecure.http.middlewares
the middlewares will be added to all the routers related to the entrypoint, but as the definition of compress-with-gzip@docker
is on a container, all the routers created before a load of this definition will produce an error.
But this error is temporary because the middleware will be loaded at some point.
There is no problem here, if you want to avoid this you have to define your middleware inside the file provider (the file provider is always the first loaded provider).
Thanks for explaining, and sorry for the false positive. This is really complex, so I want to be sure I understood you...
The reason the redirect-naked-to-www
middleware works is because it's only for the traefik container (as intended). The compress-with-gzip
middleware actually does work, but ONLY for responses from the traefik container.
So I must change docker-compose.yml
:
command:
- --entrypoints.websecure.http.middlewares=secure-headers@file,compress-with-gzip@docker
labels:
traefik.http.middlewares.compress-with-gzip.compress: true
command:
- --entrypoints.websecure.http.middlewares=secure-headers@file,compress-with-gzip@file # @file
labels:
# ...
And add another dynamic config file ./dynamic-config/compress.yml
:
http:
middlewares:
compress-with-gzip:
compress: {}
BTW I did it the way it was shown in the docs. I am using docker so I copy-pasted what was in the first visible tab.