/ traefik

#Traefik 配置http自动跳转到https

配置http与https使用相同端口

根据Traefik的文档,从v2开始,要在同一个端口上同时接收http和https请求,需要配置2个router

https://doc.traefik.io/traefik/routing/routers/#tls

示例

  routers:
    my-service-https:
      entryPoints:
        - web
      service: myservice
      rule: "Host(`myhost`)"
      tls: {}
      priority: 1
    my-service-http:
      entryPoints:
        - web
      service: myservice
      rule: "Host(`myhost`)"
      priority: 1

配置http自动跳转中间件

如果要让http请求自动重定向到https,需要配置一个redirectScheme插件

http:
  middlewares:
    redirect-https:
      redirectScheme:
        scheme: https
        permanent: true

配置http路由使用重定向插件

    my-service-http:
      entryPoints:
        - web
      service: myservice
      rule: "Host(`myhost`)"
      middlewares:
        - redirect-https      
      priority: 1

参考