Page 1 of 1

Traefik Setup

Posted: Tue Jun 22, 2021 8:37 pm
by Matt84
Hello all,

Just in case anyone else needs it, here is my docker-compose file with traefik labels.
I have added a redirect to fix the streaming issue where you would get zm/zm and it would never load.
Using this for the last month on 1.34 and then to 1.36 and had no issue so far, use ZMninja work as well.

it set up to route www.ZM.mydomain.com to www.mydomain.com/ZM
Networks are not specified below, so when added, you will need to configure a network adapter for it to use that traefik can route to.

Code: Select all

zoneminder:
    restart: always
    shm_size: 0.5gb
    image: zoneminderhq/zoneminder:latest-ubuntu18.04
    ports:
        - '8032:80'
    environment:
        - TZ=GB
        - ZM_DB_USER=$ZM_DB_USER
        - ZM_DB_PASS=$ZM_DB_PASS
        - ZM_DB_NAME=$ZM_DB_NAME
        - ZM_DB_HOST=$ZM_DB_HOST
    volumes:
        - /etc/localtime:/etc/localtime:ro
        - ./config:/config
        - /data/zmdockerdata:/var/cache/zoneminder/events
        - /data/zmdockerdata/logs:/var/log/zoneminder
    labels:
        - "traefik.enable=true"
        - "traefik.http.routers.zm.rule=Host(`zm.CHANGEME`)"
        - "traefik.http.routers.zm.entrypoints=web,websecure"
        - "traefik.http.routers.zm.service=zm"
        - "traefik.http.routers.zm.tls.certresolver=myresolver"
        - "traefik.http.services.zm.loadbalancer.server.port=80"
        - "traefik.http.middlewares.add-zm.addprefix.prefix=/zm"
        - "traefik.http.routers.zm.middlewares=add-zm@docker"
        - "traefik.http.middlewares.redirect2.redirectregex.regex=https://(.*)/zm/zm/"
        - "traefik.http.middlewares.redirect2.redirectregex.replacement=https://$${1}/"
        - "traefik.http.middlewares.all-in-one1.chain.middlewares=add-zm,redirect2"
        - "traefik.http.routers.zm.middlewares=all-in-one1@docker"

Code: Select all

api:
  dashboard: true

entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false

certificatesResolvers:
  myresolver:
    acme:
      email: CHANGEME
      storage: acme.json
      httpChallenge:
        entryPoint: web

log:
  level: DEBUG
  
  

Re: Traefik Setup

Posted: Sun Sep 19, 2021 4:05 am
by chasin_my_tail
Thanks for posting these. This is exactly what I needed. Unfortunately I still can't get mine to work. I get a "404 page not found" when I go to zm.mydomain.com
It works if I go to mydomain.com:80/zm
I figure it is either taking me to the wrong port or wrong address. In your regex line:
- "traefik.http.middlewares.redirect2.redirectregex.regex=https://(.*)/zm/zm/"

Any reason why you have /zm/zm twice? I'm am in idiot when it comes to regex, so I'm just trying to understand it.
Thanks chasin

Re: Traefik Setup

Posted: Fri Oct 15, 2021 8:12 am
by ptruman
Here is what I have, which works for me, which also includes a router for ZMNinja

Code: Select all

traefik.http.middlewares.addzm.addprefix.prefix			/zm
traefik.http.middlewares.zmcgi.replacepathregex.regex		/zm/
traefik.http.middlewares.zmcgi.replacepathregex.replacement	/
traefik.http.routers.zoneminder.entryPoints			websecure
traefik.http.routers.zoneminder.middlewares			zmcgi,addzm
traefik.http.routers.zoneminder.rule				HostHeader(`yourzm.machine.domain.etc`)
traefik.http.routers.zoneminder.tls				true
traefik.http.routers.zoneminder.tls.certresolver		yourresolver
traefik.http.routers.zoneminder.tls.domains[0].sans		*.machine.domain.etc
traefik.http.services.zoneminder.loadbalancer.server.port	80
traefik.tcp.routers.zmninja.entryPoints				zmninja
traefik.tcp.routers.zmninja.rule				HostSNI(`*`)
traefik.tcp.routers.zmninja.service				zmninja
traefik.tcp.services.zmninja.loadbalancer.server.port		9001