Last active
November 28, 2024 11:26
-
-
Save fatihyildizhan/e1d9d909049f0a67a7d1585468193438 to your computer and use it in GitHub Desktop.
Traefik v2 - How to enable gzip compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Traefik v2 docker-compose.yml | |
version: '3.7' | |
services: | |
traefik: | |
image: traefik:v2.2.7 | |
container_name: traefik | |
labels: | |
. | |
. | |
. | |
// paste on the last line to enable gzip compression | |
- "traefik.http.routers.traefik.middlewares=traefik-compress" | |
- "traefik.http.middlewares.traefik-compress.compress=true" | |
### Your container docker-compose.yml | |
version: '3.7' | |
services: | |
your_service_name: | |
image: your_image_url | |
container_name: your_container_name | |
labels: | |
. | |
. | |
. | |
// paste on the last line to enable gzip compression | |
- "traefik.http.middlewares.your_container_name_compress.compress=true" | |
- "traefik.http.routers.your_container_name.middlewares=your_container_name_compress" |
@karolzlot Did you have any updates on your config file?
traefik
service configuration
If you want to enable compression on a service, simply add to that service configuration :
labels:
[...]
+ # Enable compression
+ - "traefik.http.middlewares.{your-middleware-name}.compress=true"
+ # Reference the middleware(s) to use for that service/router
+ - "traefik.http.routers.{your-router-name}.middlewares=web-compress"
For example
services:
whoami:
image: traefik/whoami
container_name: whoami
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(``whoami.fqdn.com`)"
- "traefik.http.routers.whoami.entrypoints=websecure"
- "traefik.http.routers.whoami.tls=true"
- "traefik.http.routers.whoami.tls.certresolver=letsencrypt"
- "traefik.http.middlewares.web-compress.compress=true"
- "traefik.http.routers.whoami.middlewares=web-compress"
If you want to enable compression on all your services at once, maybe (I didn't test it, but based on the previous comment it should work) you can simply do that on the traefik
service configuration, avoiding the hassle to apply it to each other service
🔗 Official documentation (with other options, and other configuration types) : https://doc.traefik.io/traefik/middlewares/http/compress/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in my case it was enough to add two labels to traefik service, no additional labels to other containers