# Traefik Proxy

**Traefik Proxy** 是一款开源边缘路由器，同时是反向代理和负载均衡器。它能从自身运行所在的基础设施——例如 Docker 容器、[Kubernetes](https://www.edgepedia.org/zh/kubernetes) 集群或配置文件——自动发现路由配置，并在服务来来去去时实时更新路由。它用 Go 语言编写，采用 MIT 许可证，由 Traefik Labs 维护。<sup>[1](https://doc.traefik.io/traefik/v3.0/getting-started/concepts/)</sup><sup> • </sup><sup>[2](https://github.com/fabianwimberger/reverse-proxy-benchmark)</sup><sup> • </sup><sup>[3](https://traefik.io/blog/traefik-labs-incubating-the-future-of-cloud-native-networking)</sup>

| 关键事实 | 详情 |
|---|---|
| 创建 | 首行代码由 Emile Vauge 于 2015 年编写；2015 年 9 月 22 日在 Hacker News 上公开发布<sup>[4](https://traefik.io/blog/celebrating-10-years-of-traefik)</sup> |
| 核心模型 | EntryPoint 监听流量，Router 按规则匹配请求，Middleware 修改请求或响应，Service 向后端做负载均衡<sup>[1](https://doc.traefik.io/traefik/v3.0/getting-started/concepts/)</sup> |
| 配置发现 | Provider 分四类：基于标签、基于键值、基于注解、基于文件<sup>[5](https://doc.traefik.io/traefik/providers/overview/)</sup> |
| 主要版本 | v2.0 于 2019 年 9 月发布；v3.0 于 2024 年 4 月 29 日发布，新增 WebAssembly、OpenTelemetry、Kubernetes Gateway API、HTTP/3、SPIFFE 和 Tailscale 支持<sup>[6](https://traefik.io/blog/announcing-traefik-proxy-v3-rc)</sup><sup> • </sup><sup>[7](https://doc.traefik.io/traefik/deprecation/releases/)</sup> |
| 采用情况 | 截至 2026 年 7 月，官方 Docker 镜像拉取量达 35 亿次，GitHub 贡献者达 1,000 人；是 K3s 和 Canonical MicroK8s 的默认入口<sup>[8](https://traefik.io/blog/traefik-contributor-count-and-adoption-are-accelerating)</sup> |
| 证书 | 内置面向 Let's Encrypt 的 ACME 解析器；Traefik 是无状态的，因此可运行多个实例以实现高可用，但不支持多个 Traefik 2.0 实例搭配 Let's Encrypt<sup>[9](https://doc.traefik.io/traefik/master/reference/install-configuration/tls/certificate-resolvers/acme/)</sup> |
| 公司 | 由 Containous 开发，2020 年 9 月更名为 Traefik Labs<sup>[3](https://traefik.io/blog/traefik-labs-incubating-the-future-of-cloud-native-networking)</sup> |

## 起源与历史

Traefik Labs 创始人兼 CTO Emile Vauge 于 2015 年启动该项目，据他所说，出发点是对于一个高度自动化、开源、面向 DevOps 组织和微服务平台的应用代理的基本需求。他于 2015 年 9 月 22 日在 Hacker News 上发布了该项目。<sup>[4](https://traefik.io/blog/celebrating-10-years-of-traefik)</sup><sup> • </sup><sup>[3](https://traefik.io/blog/traefik-labs-incubating-the-future-of-cloud-native-networking)</sup> 最初的构想是基础设施应当自我配置：把 Traefik 指向一个编排器，它便发现服务、构建路由表，并在容器出现和消失时更新路由表，无需模板、无需生成配置、无需重载。<sup>[8](https://traefik.io/blog/traefik-contributor-count-and-adoption-are-accelerating)</sup>

项目背后的公司原名 Containous，于 2020 年 9 月更名为 Traefik Labs，当时该代理的下载量已突破 20 亿次，GitHub 星标超过 30,000 个。产品线当时包括 Traefik Proxy、Traefik Enterprise 和 Traefik Mesh。<sup>[3](https://traefik.io/blog/traefik-labs-incubating-the-future-of-cloud-native-networking)</sup> 到 2026 年 7 月，官方 Docker 镜像的拉取量已达 35 亿次，跻身 [Docker Hub](https://www.edgepedia.org/zh/docker-hub) 下载量最高的十五个官方镜像之列，第 1,000 名贡献者也提交了改动；而在项目的第一年，只有十四个人提交过代码。<sup>[8](https://traefik.io/blog/traefik-contributor-count-and-adoption-are-accelerating)</sup>

## 架构

Traefik 自称边缘路由器：它是平台的大门，拦截每一个进入的请求，并根据路径、主机、请求头等类似条件，应用规则来决定由哪个服务处理该请求。四个组件定义了这一模型。<sup>[1](https://doc.traefik.io/traefik/v3.0/getting-started/concepts/)</sup>

- **EntryPoint** 是进入 Traefik 的网络入口点。它们定义接收数据包的端口，以及监听的是 TCP 还是 UDP；在 Helm chart 中，默认创建 `web`（端口 80）、`websecure`（端口 443）、`traefik`（端口 8080）和 `metrics`（端口 9100）这几个 entryPoint。<sup>[1](https://doc.traefik.io/traefik/v3.0/getting-started/concepts/)</sup><sup> • </sup><sup>[10](https://doc.traefik.io/traefik/routing/entrypoints/)</sup>
- **Router** 将进入的请求连接到能够处理它们的服务，分析主机、路径、请求头和 TLS。<sup>[1](https://doc.traefik.io/traefik/v3.0/getting-started/concepts/)</sup><sup> • </sup><sup>[11](https://doc.traefik.io/traefik/v3.3/routing/overview/)</sup>
- **Middleware** 在请求到达服务之前修改请求或响应。它们可以挂在路由器级别，作用于匹配该路由器规则的所有请求；也可以挂在服务级别，作用于该服务处理的一切；两者同时配置时，路由器中间件先执行。可用的中间件能修改请求和请求头、执行重定向、添加认证等，同协议的中间件可以组合成链。<sup>[1](https://doc.traefik.io/traefik/v3.0/getting-started/concepts/)</sup><sup> • </sup><sup>[12](https://doc.traefik.io/traefik/middlewares/overview/)</sup>
- **Service** 配置如何到达实际后端，包括负载均衡。<sup>[1](https://doc.traefik.io/traefik/v3.0/getting-started/concepts/)</sup>

Traefik 将安装配置（旧称静态配置，用于设置 provider 和 entrypoint）与路由配置（旧称动态配置，用于定义 router、service 和 middleware，且无需重启代理即可变更）分开。<sup>[13](https://doc.traefik.io/traefik/v3.3/reference/routing-configuration/dynamic-configuration-methods/)</sup>

## Provider 与服务发现

配置发现通过 provider 实现，provider 是编排器、容器引擎、云提供商或键值存储之类的基础设施组件。Traefik 向 provider 的 API 查询路由信息，并在检测到变化时动态更新路由。Provider 分为四类：基于标签，即每个部署的容器携带一组标签；基于键值，即容器更新一个存储；基于注解，即一个单独的带注解对象定义容器的特征；以及基于文件。<sup>[5](https://doc.traefik.io/traefik/providers/overview/)</sup> 实践中，文件 provider 使用 TOML 或 YAML 文件，Docker 和 ECS provider 使用容器标签，Kubernetes provider 使用注解，KV provider 使用键值对。<sup>[13](https://doc.traefik.io/traefik/v3.3/reference/routing-configuration/dynamic-configuration-methods/)</sup>

动态配置中声明的对象，如 middleware、service、TLS 选项或服务器传输，都位于其 provider 的命名空间中；用 Docker 标签声明的 middleware 位于 Docker provider 命名空间，可以跨 provider 引用，例如从 Kubernetes 注解中引用 `add-foo-prefix@file`。<sup>[5](https://doc.traefik.io/traefik/providers/overview/)</sup>

Docker provider 需要访问 Docker socket 以监视 Docker API，文档将此标记为安全隐患：如果处理外部请求的 Traefik 进程遭到攻击，攻击者就能触及 Docker 后端。文档给出的变通办法包括通过 TCP 暴露 socket 并启用客户端证书认证、使用 socket-proxy 容器，以及内核级限制。<sup>[14](https://doc.traefik.io/traefik/v1.7/configuration/backends/docker/)</sup>

## TLS 与证书管理

Traefik 内置面向 [Let's Encrypt](https://www.edgepedia.org/zh/lets-encrypt) 的 ACME 证书解析器，可按证书解析器配置 External Account Binding 密钥等选项。按设计，Traefik 是一个从环境中推导配置的无状态应用，因此可运行多个实例以实现高可用，这在 Kubernetes 中是常见模式。单实例搭配 Let's Encrypt 没有问题，但无法运行多个启用了 Let's Encrypt 的 Traefik 2.0 实例，因为无法确保正确的实例收到质询请求和响应；早期的 v1.x 版本为此使用 KV 存储，该功能在 2.0 中被移除。对于高可用证书，文档推荐使用带分布式 Let's Encrypt 的 Traefik Enterprise，或 Cert-Manager 之类的证书控制器。如果无法访问 Let's Encrypt，Traefik 会依次回退到先前生成的 ACME 证书、已过期的 ACME 证书，再到提供的证书。<sup>[9](https://doc.traefik.io/traefik/master/reference/install-configuration/tls/certificate-resolvers/acme/)</sup>

## 版本与支持

项目遵循语义化版本，并为每个次版本维护单独的分支。按 v3.6 的规则，每个次版本自 GA 日期起支持六个月，新大版本发布后，上一大版本的最后一个次版本继续获得两年支持。3.0 版于 2024 年 4 月 29 日发布；3.7 版于 2026 年 5 月 5 日发布，处于活跃支持中；2.11 分支于 2024 年 2 月 12 日发布，安全支持持续到 2026 年 9 月 7 日。<sup>[7](https://doc.traefik.io/traefik/deprecation/releases/)</sup>

2024 年 2 月宣布的 3.0 版新增了通过 http-wasm ABI 对 [WebAssembly](https://www.edgepedia.org/zh/webassembly) 插件的支持，以及对 OpenTelemetry 和 Kubernetes Gateway API 的支持，并新增了 HTTP/3、SPIFFE 和 [Tailscale](https://www.edgepedia.org/zh/tailscale) 支持。它还保留了 2019 年随 v2 引入的 Yaegi 解释器，让用户可以用 Go 编写中间件；当时通过其目录可获取一百多个社区中间件。<sup>[6](https://traefik.io/blog/announcing-traefik-proxy-v3-rc)</sup>

## 采用情况与 Ingress NGINX 退役

2020 年的一项 CNCF 调查显示，Traefik 的入口 provider 使用率为 17%，落后于 NGINX 的 62%、Envoy 的 37% 和 HAProxy 的 27%。<sup>[15](https://wtit.com/wp-content/uploads/2022/01/CNCF_Survey_Report_2020.pdf)</sup> 此后平台厂商纷纷将其采纳为默认：Rancher 的 [K3s](https://www.edgepedia.org/zh/k3s) 从一开始就随附 Traefik 作为开箱即用的入口，Nutanix 将其作为 Kubernetes 平台的标准组件，Canonical MicroK8s 将其作为默认入口控制器随附，RKE2 从 v1.36 起将其采纳为默认。<sup>[8](https://traefik.io/blog/traefik-contributor-count-and-adoption-are-accelerating)</sup>

Kubernetes SIG Network 和安全响应委员会宣布 Ingress NGINX 将于 2026 年 3 月退役，据委员会引用的 Datadog 内部研究，这影响了大约一半的云原生环境。<sup>[16](https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/)</sup> Traefik 的回应是推出自己的原生 NGINX Ingress provider，它可以读取已有的 Ingress 资源及其 `nginx.ingress.kubernetes.io` 注解——超过 80 个——无需任何转换或重写 YAML；3.7 版提供了其中 85 个或更多注解。Traefik 可以在同一实例上并行运行传统 Ingress、NGINX 注解和 Gateway API。<sup>[8](https://traefik.io/blog/traefik-contributor-count-and-adoption-are-accelerating)</sup>

## 性能

实测结果在很大程度上取决于工作负载和配置。在一项针对轮询算法 HTTP 负载均衡的学术评估中，Traefik 的表现比 NGINX 好 13.2%，而 Envoy 好 13.8%，HAProxy 好 77.2%。<sup>[17](https://www.diva-portal.org/smash/get/diva2%3A1678660/FULLTEXT01.pdf)</sup> 一项基于 Docker 的基准测试使用 Vegeta、约 20 KB 的 JSON 负载、每秒 5,000 个请求，发现四个代理在 HTTP/1.1 上的差距都在约 5% 以内，Traefik 在 HTTPS/1.1 和 [HTTP/2](https://www.edgepedia.org/zh/http-2) 场景中录得最低的平均延迟和 P99 延迟，所有代理的成功率均为 100%。<sup>[2](https://github.com/fabianwimberger/reverse-proxy-benchmark)</sup> 只在单方更改默认值、TLS 设置或中间件的对比会产生不同结果，因此基准数字应结合所测试的具体配置来解读。<sup>[2](https://github.com/fabianwimberger/reverse-proxy-benchmark)</sup>

## 安全

已公布的漏洞说明了项目在受支持分支中修补的问题类型。Traefik 2.11.40 及更早版本、3.0.0-beta1 至 3.6.11、以及 3.7.0-ea.1 均受 CVE-2026-32305 影响，该缺陷在 ClientHello 数据包被分片时，可让攻击者通过 TLS SNI 预嗅探逻辑绕过 mTLS。<sup>[18](https://isomer-user-content.by.gov.sg/36/0bd72b6b-eb30-49d4-aba4-f136d5d20ba9/25_Mar_2026.pdf)</sup> StripPrefix 中间件中的一个高危漏洞（已在 2.11.48、3.6.19 和 3.7.3 之前的版本中修复）允许未经认证的攻击者绕过路由级别的认证和授权。<sup>[19](https://isomer-user-content.by.gov.sg/36/bc7af69f-20ec-46a8-a5a2-f8fc4e6fa413/24_Jun_2026.pdf)</sup>

## 运维

Traefik 提供 REST API 和 Web 仪表板，其端点列出 HTTP、TCP 和 UDP 的 router、service、middleware 和 entrypoint，另有 `/api/overview` 提供统计信息、`/api/rawdata` 提供完整的动态配置；调试端点暴露 Go 的 `expvar` 和 `pprof` 数据。<sup>[20](https://doc.traefik.io/traefik/operations/api/)</sup> 当请求不匹配任何 router 时，Traefik 返回 `404 Not Found` 而非 `503 Service Unavailable`，因为它无法确认缺少匹配 router 是暂时性的。<sup>[21](https://doc.traefik.io/traefik/getting-started/faq/)</sup>

## References

1. [Concepts, Traefik v3.0 documentation](https://doc.traefik.io/traefik/v3.0/getting-started/concepts/)
2. [Reverse Proxy Benchmark (Nginx, Caddy, Traefik, HAProxy), fabianwimberger, GitHub](https://github.com/fabianwimberger/reverse-proxy-benchmark)
3. [Traefik Labs: Incubating the Future of Cloud Native Networking, Emile Vauge, September 23, 2020](https://traefik.io/blog/traefik-labs-incubating-the-future-of-cloud-native-networking)
4. [Aged to Perfection: Traefik's 10-Year Journey from Zero to Standard, Emile Vauge, September 22, 2025](https://traefik.io/blog/celebrating-10-years-of-traefik)
5. [Traefik Providers Overview, Traefik documentation](https://doc.traefik.io/traefik/providers/overview/)
6. [Announcing Traefik Proxy v3.0 RC1, Emile Vauge, February 14, 2024](https://traefik.io/blog/announcing-traefik-proxy-v3-rc)
7. [Releases, Traefik documentation](https://doc.traefik.io/traefik/deprecation/releases/)
8. [Traefik Reached 3.5B Downloads and 1,000 Contributors, Traefik blog](https://traefik.io/blog/traefik-contributor-count-and-adoption-are-accelerating)
9. [Traefik & ACME Certificates Resolver, Traefik documentation](https://doc.traefik.io/traefik/master/reference/install-configuration/tls/certificate-resolvers/acme/)
10. [Traefik EntryPoints, Traefik documentation](https://doc.traefik.io/traefik/routing/entrypoints/)
11. [Routing & Load Balancing Overview, Traefik v3.3 documentation](https://doc.traefik.io/traefik/v3.3/routing/overview/)
12. [HTTP Middleware Overview, Traefik documentation](https://doc.traefik.io/traefik/middlewares/overview/)
13. [Providing Dynamic (Routing) Configuration to Traefik, Traefik v3.3 documentation](https://doc.traefik.io/traefik/v3.3/reference/routing-configuration/dynamic-configuration-methods/)
14. [Traefik & Docker (v1.7): Security Challenge with the Docker Socket, Traefik documentation](https://doc.traefik.io/traefik/v1.7/configuration/backends/docker/)
15. [CNCF Survey Report 2020, Service Proxy](https://wtit.com/wp-content/uploads/2022/01/CNCF_Survey_Report_2020.pdf)
16. [Ingress NGINX Retirement: What You Need to Know, Kubernetes blog, November 11, 2025](https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/)
17. [HTTP Load Balancing Performance Evaluation of HAProxy, NGINX, Traefik and Envoy with the Round-Robin Algorithm, DiVA portal](https://www.diva-portal.org/smash/get/diva2%3A1678660/FULLTEXT01.pdf)
18. [Vulnerability bulletin listing CVE-2026-32305, Singapore government security advisory, March 2026](https://isomer-user-content.by.gov.sg/36/0bd72b6b-eb30-49d4-aba4-f136d5d20ba9/25_Mar_2026.pdf)
19. [Vulnerability bulletin listing the StripPrefix middleware vulnerability, Singapore government security advisory, June 2026](https://isomer-user-content.by.gov.sg/36/bc7af69f-20ec-46a8-a5a2-f8fc4e6fa413/24_Jun_2026.pdf)
20. [Traefik API & Dashboard, Traefik documentation](https://doc.traefik.io/traefik/operations/api/)
21. [Traefik Getting Started FAQ, Traefik documentation](https://doc.traefik.io/traefik/getting-started/faq/)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/traefik-proxy

English original: https://www.edgepedia.org/traefik-proxy
