使用 Traefik 作为反向代理并带 HTTP 基本认证的 Syncthing docker-compose 设置

此设置使用基于 docker-composesyncthing 设置和 Traefik 作为反向代理。HTTP 基本认证用于防止对 syncthing Web UI 的未授权访问。或者,你可以使用内置的密码保护。

查看 使用 Lets Encrypt Cloudflare DNS-01 & TLS-ALPN-01 & HTTP-01 挑战的简单 Traefik docker-compose 设置 了解我的 Traefik HTTPS 设置。

docker-compose.syncthing.yml
services:
  syncthing:
    image: syncthing/syncthing
    hostname: Syncthing-Myserver
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - ./syncthing_data:/var/syncthing
    ports: # NOTE: 8384 not forwarded, this is handled by traefik
      - "22000:22000"
      - "21027:21027/udp"
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.syncthing.rule=Host(`syncthing.myserver.net`)"
      - "traefik.http.routers.syncthing.entrypoints=websecure"
      - "traefik.http.routers.syncthing.tls.certresolver=cloudflare"
      - "traefik.http.routers.syncthing.tls.domains[0].main=myserver.net"
      - "traefik.http.routers.syncthing.tls.domains[0].sans=*.myserver.net"
      - "traefik.http.services.syncthing.loadbalancer.server.port=8384"
      - "traefik.http.routers.syncthing.middlewares=syncthing-auth"
      # Auth (this is shared with the server). NOTE: generate with "htpasswd -n admin" and REPLACE EVERY "$" by "$$" IN THE OUTPUT!
      - "traefik.http.middlewares.syncthing-auth.basicauth.users=admin:$$apr1$$ehr8oqEZ$$tHoOVLG19oHdUe81IeePo1
"

Check out similar posts by category: Docker, Traefik