简体   繁体   中英

Traefik v2 - Enable gzip compression

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM