How to use Traefik for WebSocket backend

2019-07-13 06:51发布

问题:

I am trying to configure Traefik for a WebSocket app, I just try with a simple WS app on docker: https://hub.docker.com/r/jmalloc/echo-server/

To test it I use Chrome SimpleWebSocketClient, so if I use the IP:Port of the app it works fine. If I add the Traefik DNS it fails, I just try with other WS server and clients and fails too, so it would be something of Traefik.

I just try with Traefik versions:

-v1.3.0/raclette
-v1.2.3/morbier

Those are my Traefik rules:

[backends.ws-test-backend]
    [backends.ws-test-backend.LoadBalancer]
      method = "drr"
    [backends.ws-test-backend.servers.server1]
    url = "ws://172.16.8.231:3000"

[frontends.ws-test-frontend]
  backend = "ws-test-backend"
  passHostHeader = true
  entrypoints = ["http","https","ws", "wss"]
    [frontends.ws-test-frontend.routes.manager]
    rule = "Host:ws-test.ikcloud.ikerlan.es"

What could it be wrong? Any recommended reverse proxy for doing this?

回答1:

You need to enable sticky session for your ws connections, otherwise it will be reconnecting all the time.

[backends]
  [backends.backend1]
    # Enable sticky session
    [backends.backend1.loadbalancer.stickiness]