Skip to content

Instantly share code, notes, and snippets.

@gimiki
Last active September 2, 2025 18:47
Show Gist options
  • Select an option

  • Save gimiki/628e2ca10f026975f00f34e4d1f4ff23 to your computer and use it in GitHub Desktop.

Select an option

Save gimiki/628e2ca10f026975f00f34e4d1f4ff23 to your computer and use it in GitHub Desktop.

Revisions

  1. gimiki revised this gist Jan 21, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions traefik_tcp_mqtt_mosquitto_docker_compose.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@ This gist is to configure a Mosquitto MQTT Broker behind a Traefik reverse-proxy
    Mosquitto will be configuread as a TCP Service.

    This is a simple configuration used on the same single server. Probably to be adapted for other cases.
    Having mosquitto behind a reverse proxy enables you to configure TLS on Traefik (likely you already do that for other applications as well) and to load balance different MQTT instances, but that goes beyond this gist.

    As noted in Traefik docs, in the router you must use the rule ``HostSNI(`*`)`` when using non-TLS routers like in this example. Ref. https://docs.traefik.io/routing/routers/#rule_1

  2. gimiki revised this gist Mar 19, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions traefik_tcp_mqtt_mosquitto_docker_compose.md
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,8 @@ Mosquitto will be configuread as a TCP Service.

    This is a simple configuration used on the same single server. Probably to be adapted for other cases.

    As noted in Traefik docs, in the router you must use the rule ``HostSNI(`*`)`` when using non-TLS routers like in this example. Ref. https://docs.traefik.io/routing/routers/#rule_1

    docker-compose.yml
    ```
    networks:
  3. gimiki renamed this gist Mar 19, 2020. 1 changed file with 0 additions and 0 deletions.
  4. gimiki revised this gist Mar 19, 2020. No changes.
  5. gimiki revised this gist Mar 19, 2020. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@
    This gist is to configure a Mosquitto MQTT Broker behind Traefik reverse-proxy, both in a docker container.
    This gist is to configure a Mosquitto MQTT Broker behind a Traefik reverse-proxy, both in a docker container.
    Mosquitto will be configuread as a TCP Service.

    This is the dockerfile:
    This is a simple configuration used on the same single server. Probably to be adapted for other cases.

    docker-compose.yml
    ```
    networks:
    mqtt:
  6. gimiki created this gist Mar 19, 2020.
    58 changes: 58 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    This gist is to configure a Mosquitto MQTT Broker behind Traefik reverse-proxy, both in a docker container.

    This is the dockerfile:

    ```
    networks:
    mqtt:
    driver: bridge
    services:
    reverse-proxy:
    image: traefik:latest
    container_name: "traefik"
    # Enables the web UI
    command:
    - "--log.level=DEBUG"
    - "--providers.docker=true"
    - "--providers.docker.exposedByDefault=false"
    - "--entrypoints.mqtt.address=:1883"
    - "--entrypoints.websocket.address=:9001"
    ports:
    # Mosquitto
    - "1883:1883"
    - "9001:9001"
    volumes:
    # So that Traefix can listen to the Docker events
    - /var/run/docker.sock:/var/run/docker.sock
    networks:
    - mqtt
    mqtt:
    container_name: mqtt
    image: eclipse-mosquitto
    networks:
    - mqtt
    restart: always
    expose:
    - 1883
    - 9001
    volumes:
    - "mqtt:/mosquitto/"
    labels:
    - "traefik.enable=true"
    - "traefik.docker.network=mqtt"
    - "traefik.tcp.services.mqtt.loadbalancer.server.port=1883"
    - "traefik.tcp.services.mqtt_websocket.loadbalancer.server.port=9001"
    - "traefik.tcp.routers.tcpr_mqtt.entrypoints=mqtt"
    - "traefik.tcp.routers.tcpr_mqtt.rule=HostSNI(`*`)"
    - "traefik.tcp.routers.tcpr_mqtt.service=mqtt"
    - "traefik.tcp.routers.tcpr_mqtt_websocket.entrypoints=websocket"
    - "traefik.tcp.routers.tcpr_mqtt_websocket.rule=HostSNI(`*`)"
    - "traefik.tcp.routers.tcpr_mqtt_websocket.service=mqtt_websocket"
    version: "3.4"
    volumes:
    mqtt: ~
    ```