首页 > 解决方案 > 如何通过 docker 容器中的 traefik 发布 websocket

问题描述

我在我的 docker swarm 中运行 traefik,为几个网站做 https 代理,这部分工作正常。

问题是我有一个只发布 WSS (mosquitto) 的容器,用于我的家庭自动化设置,但我无法让它工作。

在我的自动化堆栈 yml 文件中,我有以下关于 mosquitto 的节,从我在各个页面上阅读的内容来看,我只需要将 HTTPS 指定为协议,因为它还涵盖 WSS

  mqtt:
    deploy:
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s

      placement:
        constraints:
          - node.labels.mysensors==yes
      replicas: 1
    labels:
        - traefik.frontend.rule=Host:mqtt.mydomain.com
        - traefik.port=9001
        - traefik.docker.network=traefik-public
        - traefik.enable=true
        - traefik.redirectorservice.frontend.entryPoints=http
        - traefik.redirectorservice.frontend.redirect.entryPoint=https
        - traefik.frontend.whiteList.sourceRange=192.168.0.0/16
        - traefik.tags=traefik-public
        - traefik.webservice.frontend.entryPoints=https
    ports:
      - 1883:1883
    networks:
      - homeautomation
      - traefik-public
    volumes:
      - /opt/mosquitto:/mosquitto
    image: "eclipse-mosquitto:1.4.12"

在我的 Traefik 仪表板中,我只看到其他 (https) 服务后端暴露,而不是这个 WSS 后端。想知道我的配置中缺少什么。

标签: traefik

解决方案


添加标签:

- traefik.backend.loadbalancer.stickiness: "true"

这将允许支持 wss 连接


推荐阅读