Traefik 入口点(EntryPoints)文档
入口点(EntryPoints)
入口点是 Traefik 的网络入口点。它们定义接收数据包的端口,以及是监听 TCP 还是 UDP。
配置示例
YAML 格式:
yaml
entryPoints:
web:
address: :80
http:
redirections:
entryPoint:
to: websecure
scheme: https
permanent: true
observability:
accessLogs: false
metrics: false
tracing: false
websecure:
address: :443
http:
tls: {}
middlewares:
- auth@kubernetescrd
- strip@kubernetescrdTOML 格式:
toml
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
permanent = true
[entryPoints.web.observability]
accessLogs = false
metrics = false
tracing = false
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http]
tls = {}
middlewares = ["auth@kubernetescrd", "strip@kubernetescrd"]配置选项
address
| 字段 | 描述 | 默认值 | 必填 |
|---|---|---|---|
address | 监听地址和端口(如 :80、0.0.0.0:443、192.168.1.10:8080)。 | - | 是 |
asDefault
| 字段 | 描述 | 默认值 | 必填 |
|---|---|---|---|
asDefault | 设为默认入口点(未显式指定入口点的路由器会使用此入口点)。 | false | 否 |
observability
| 字段 | 描述 | 默认值 | 必填 |
|---|---|---|---|
observability.accessLogs | 是否为该入口点启用访问日志。 | true | 否 |
observability.metrics | 是否为该入口点启用指标。 | true | 否 |
observability.tracing | 是否为该入口点启用链路追踪。 | true | 否 |
http
| 字段 | 描述 | 默认值 | 必填 |
|---|---|---|---|
http.redirections.entryPoint.to | 重定向到的目标入口点。 | - | 否 |
http.redirections.entryPoint.scheme | 重定向的协议。 | - | 否 |
http.redirections.entryPoint.permanent | 永久重定向。 | false | 否 |
http.tls | TLS 配置。 | - | 否 |
http.middlewares | 默认中间件列表(按顺序)。 | [] | 否 |
http.forwardedHeaders | 信任的前向头(用于识别原始客户端)。 | - | 否 |
http.encodeQuerySemicolons | 解码分号。 | - | 否 |
http.secureJson | 渲染安全 JSON 响应。 | false | 否 |
transport
| 字段 | 描述 | 默认值 | 必填 |
|---|---|---|---|
transport.respondingTimeouts.readTimeout | 读取响应体的最大持续时间。 | 0 | 否 |
transport.respondingTimeouts.writeTimeout | 写入响应体的最大持续时间。 | 0 | 否 |
transport.respondingTimeouts.idleTimeout | 空闲连接超时。 | 180s | 否 |
transport.lifeCycle.requestAcceptGraceTimeout | 优雅停止期间等待请求接受的最大时间。 | 0 | 否 |
transport.lifeCycle.graceTimeOut | 收到停止信号后等待正在进行的请求完成的最长时间。 | 0 | 否 |
transport.keepAliveMaxRequests | keep-alive 连接可服务的最大请求数。 | 0 | 否 |
transport.keepAliveMaxTime | keep-alive 连接的最大空闲时间。 | 0 | 否 |
proxyProtocol
| 字段 | 描述 | 默认值 | 必填 |
|---|---|---|---|
proxyProtocol | 启用 PROXY 协议(用于从上游 LB 获取真实客户端 IP)。 | - | 否 |
proxyProtocol.version | PROXY 协议版本(1 或 2)。 | 1 | 否 |
通用场景
启用 HTTP → HTTPS 重定向
yaml
entryPoints:
web:
address: :80
http:
redirections:
entryPoint:
to: websecure
scheme: https
permanent: true启用 TLS
yaml
entryPoints:
websecure:
address: :443
http:
tls: {}启用 mTLS
yaml
entryPoints:
websecure:
address: :443
http:
tls:
clientAuth:
secretNames:
- my-client-ca接受 PROXY 协议
yaml
entryPoints:
behind-lb:
address: :443
proxyProtocol: {}适用场景
- 多端口监听:在同一实例上同时监听 HTTP 和 HTTPS
- 多协议:同时支持 HTTP、TCP、UDP
- 环境隔离:为不同环境配置不同入口点
- 多个 TLS 域:在同一 HTTPS 端口上提供多个域
在生产环境使用 Traefik OSS?
如果你在工作中使用 Traefik,可以考虑为其添加企业级 API 网关能力或获取 Traefik OSS 的商业支持。