0

I struggled on this for at least the last day and didn't found a solution. I want to connect Websocket and https on the same docker. I have tried many thing. Here is my configuration:

Traefik V2 first :

here is the docker container

version: '3'

services:
  reverse-proxy:
    image: traefik:v2.7.1
    container_name: traefik
    ports:
      - "80:80"
      - "443:443"
    
  volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - $PWD/traefik.toml:/etc/traefik/traefik.toml
      - $PWD/acme.json:/acme.json
    restart: always
    networks:
      - web
networks:
  web:
    external:
      name: web
~                

here is my toml file

[accessLog]
[api]
  dashboard = true
  insecure = true
[log]
  level = 'ERROR'
[entryPoints]
  [entryPoints.web]
    address = ":80"
    [entryPoints.web.http]
      [entryPoints.web.http.redirections]
        [entryPoints.web.http.redirections.entryPoint]
          to = "websecure"
          scheme = "https"
          permanent = true

  [entryPoints.websecure]
    address = ":443"
      [entryPoints.websecure.http.tls]
        certResolver = "default"
  [entryPoints.wss]
    address = ":8000"

 [providers]
  [providers.docker]
    watch = true
    exposedByDefault = false
    network = "web"

[certificatesResolvers]
  [certificatesResolvers.default]
    [certificatesResolvers.default.acme]
      email = "contact@queel.io"
      storage = "acme.json"
      caServer = "https://acme-v01.api.letsencrypt.org/directory"
    [certificatesResolvers.default.acme.tlsChallenge]


I want to connect on https and wss on the same node container exposing two ports here is my docker-compose for this

 node:
    build: ./docker/node_api
    volumes:
      - ./node:/src
    tty: true
    networks:
      - web
    ports:
      - ":8000"
      - ":8081"
    labels:
      - "traefik.docker.network=web"
      - "traefik.enable=true"
      - "traefik.http.routers.node.rule=Host(`api.${HOST}`)"
      - "traefik.http.routers.node.entrypoints=websecure"
      - "traefik.tcp.services.node.loadbalancer.server.port=8000"
      - "traefik.http.routers.wss.rule=Host(`ws.${HOST}`)"
      - "traefik.tcp.services.wss.loadbalancer.server.port=8081"
        #- "traefik.http.services.wss.loadBalancer.sticky.cookie=true"
        # - "traefik.http.routers.wss.tls=true"
        #- "traefik.http.routers.wss.tls.certResolver=default"
        #- "traefik.http.routers.wss.entrypoints=wss"
      - "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https"
        #- "traefik.http.routers.wss.tls.certresolver=default"
    depends_on:
      - elastic
      - neo
    working_dir: /src


Has you can see I tried many solutions, but none is working, maybe you should help me find the combination of the goog ones. It seems has I have seen elsewhere that the X-Forwarded-Proto is the solution. For new the wss connection is not working

Could you help me with that

user2626210
  • 115
  • 5
  • 13

1 Answers1

0

The anwser is quite simple, my socket server was not started. The config stay the same for the main part and I have only to have :

- "traefik.http.routers.wss.rule=Host(`ws.${HOST}`)"
- "traefik.tcp.services.wss.loadbalancer.server.port=8081"
- "traefik.http.routers.wss.entrypoints=websecure"

entrypoint=websecure is enought for wss since it's over http.

I didn't manage to use the two service in a single container so i swapped the container in two container.

user2626210
  • 115
  • 5
  • 13