Traefik v2 - 启用 gzip 压缩

fat*_*han 3 nginx docker docker-compose traefik

我正在使用 Traefik v2 运行 Docker 容器。该容器与 Nginx 一起提供服务,我需要在 Traefik v2 上启用 gzip 压缩。

我无法通过更改 Nginx app.config 文件来实现它。

我添加了这些类型的标签,但它不起作用。

gzip on;
gzip_types images, CSS, js etc.
Run Code Online (Sandbox Code Playgroud)

如何在 Traefik v2 上启用 gzip?

fat*_*han 7

我认为这是启用 gzip最简单的方法。

打开 Traefik v2docker-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"
Run Code Online (Sandbox Code Playgroud)

打开容器的 docker-compose.yml 并添加以下行:

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"
Run Code Online (Sandbox Code Playgroud)

然后,运行这两个docker-compose.yml文件。

您还可以找到此解决方案作为要点:https://gist.github.com/fatihyildizhan/e1d9d909049f0a67a7d1585468193438

Let's Encrypt 的完整 Traefik v1 和 v2 安装指南:https://gist.github.com/fatihyildizhan/8f124039a9bd3801f0caf3c01c3601fb

2023 年 5 月 18 日更新:Docker 23 + Traefik 2.9.10 and v1.7 + Let's Encrypt + Github Registry V2 ghcr.io