Traefik v2 - Enable gzip compression

Viewed 2446

I am using Traefik v2 to running a Docker container. This container is serving with Nginx and I need to enable gzip compression on Traefik v2.

I couldn't achieve it by changing the Nginx app.config file.

I added these kinds of tags but it didn't work.

gzip on;
gzip_types images, CSS, js etc.

How can I enable gzip on a Traefik v2?

1 Answers

I think this is the Simplest way to enable gzip.

Open Traefik v2 docker-compose.yml and add these lines:

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"

Open Your Container's docker-compose.yml and add these lines:

version: '3.7'

services:
    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"

Then, run your both docker-compose.yml files.

You may also find this solution as a Gist: https://gist.github.com/fatihyildizhan/e1d9d909049f0a67a7d1585468193438

Full Traefik v1 and v2 install guide with Let's Encrypt: https://gist.github.com/fatihyildizhan/8f124039a9bd3801f0caf3c01c3601fb

Related