How to make WebSockets work with Traefik 2.0 (setting up Rancher)

How can I make websockets work? I am trying to deploy rancher in a normal docker environment:

traefik.http.routers.rancher-secure.entrypoints: web-secure
traefik.http.routers.rancher-secure.rule: Host(`rancher.mydomain.de`)
traefik.http.routers.rancher-secure.tls.certResolver: lets-encrypt
traefik.http.routers.rancher.entrypoints: web
traefik.http.routers.rancher.middlewares: redirect@file
traefik.http.routers.rancher.rule: Host(`rancher.mydomain.de`)

Found the solution, just add that middleware to your secure endpoint route:

traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto = https
3 Likes

Thx you, you save me :slight_smile:

An example with kubernetes if this can help:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: svc-rancher-http
  namespace: cattle-system
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`rancher.example.com`)
      middlewares:
        - name: svc-rancher-redirectscheme-to-https
      kind: Rule
      services:
        - name: rancher
          port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: svc-rancher-https
  namespace: cattle-system
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`rancher.example.com`)
      middlewares:
        - name: svc-rancher-headers
      kind: Rule
      services:
        - name: rancher
          port: 80
  tls:
    certResolver: default
    options: {}
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: svc-rancher-redirectscheme-to-https
  namespace: cattle-system
spec:
  redirectScheme:
    scheme: https
    permanent: true
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: svc-rancher-headers
spec:
  headers:
    customRequestHeaders:
      X-Forwarded-Proto: "https"

``̀
1 Like

Here I've analyzed in deep why this will happen, just for those who are interested in.

thanks, this example got me on the road to finish everything :slight_smile: