Skip to content

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@kubernetescrd

TOML 格式:

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监听地址和端口(如 :800.0.0.0:443192.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.tlsTLS 配置。-
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.keepAliveMaxRequestskeep-alive 连接可服务的最大请求数。0
transport.keepAliveMaxTimekeep-alive 连接的最大空闲时间。0

proxyProtocol

字段描述默认值必填
proxyProtocol启用 PROXY 协议(用于从上游 LB 获取真实客户端 IP)。-
proxyProtocol.versionPROXY 协议版本(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 的商业支持。

基于 MIT 协议发布