首页 文章

Traefik>某些容器的“Bad gateway”(错误502)

提问于
浏览
3

我遇到了一些使用traefik和docker的问题,我不知道为什么 .

对于某些容器,它就像魅力和其他容器一样,当我尝试访问这些容器时出错:错误的网关(错误502) .

这是我的traefik.toml:

# Service logs (here debug mode)
debug = true
logLevel = "DEBUG"

defaultEntryPoints = ["http", "https"]

# Access log
filePath = "/var/log/traefik/access.log"
format = "common"

################################################################
# Web configuration backend
################################################################
[web]
address = ":8080"

################################################################
# Entry-points configuration
################################################################
[entryPoints]
  [entryPoints.http]
    address = ":80"
    [entryPoints.http.redirect]
      entryPoint = "https"
  [entryPoints.https]
    address = ":443"
    [entryPoints.https.tls]

################################################################
# Docker configuration backend
################################################################
[docker]
domain = "domain.tld"
watch = true
exposedbydefault = false
endpoint = "unix:///var/run/docker.sock"

################################################################
# Let's encrypt
################################################################
[acme]
email = "admin@domain.tld"
storageFile = "acme.json"
onDemand = false
onHostRule = true
entryPoint = "https"

[acme.httpChallenge]
  entryPoint = "http"

[[acme.domains]]
  main = "domain.tld"
  sans = ["docker.domain.tld", "traefik.domain.tld", "phpmyadmin.domain.tld", "perso.domain.tld", "muximux.domain.tld", "wekan.domain.tld", "wiki.domain.tld", "cloud.domain.tld", "email.domain.tld"]

这是我的docker-compose.yml(对于portainer,它是一个有效的容器):

version: '2'

services:
  portainer:
    restart: always
    image: portainer/portainer:latest
    container_name: "portainer"
#Automatically choose 'Manage the Docker instance where Portainer is running' by adding <--host=unix:///var/run/docker.sock> to the command
    ports:
      - "9000:9000"
    networks:
      - traefik-network
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ../portainer:/data
    labels:
      - traefik.enable=true
      - traefik.backend=portainer
      - traefik.frontend.rule=Host:docker.domain.tld
      - traefik.docker.network=traefik-network
      - traefik.port=9000
      - traefik.default.protocol=http

networks:
  traefik-network:
    external : true

如果我去docker.domain.tld,它可以工作!并在https中,使用valide让加密证书:)

这是我的docker-compose.yml(对于dokuwiki,这是一个不起作用的容器):

version: '2'

services:
  dokuwiki:
    container_name: "dokuwiki"
    image: bitnami/dokuwiki:latest
    restart: always
    volumes:
      - ../dokuwiki/data:/bitnami
    ports:
      - "8085:80"
      - "7443:443"
    networks:
      - traefik-network
    labels:
      - traefik.backend=dokuwiki
      - traefik.docker.network=traefik-network
      - traefik.frontend.rule=Host:wiki.domain.tld
      - traefik.enable=true
      - traefik.port=8085
      - traefik.default.protocol=http

networks:
  traefik-network:
    external: true

如果我去wiki.domain.tld,它不起作用!我在浏览器上遇到错误的网关错误 . 我试图将traefik.port更改为7443并将traefik.default.protocol更改为https但我有相同的错误...当我尝试使用IP和端口访问wiki时(当然,它在http /中) HTTPS) . 只有当我输入wiki.domain.tld时,我的网关才会出错 .

所以,我不明白为什么它适用于某些容器而不适用于具有相同声明的其他容器 .

你可以帮帮我吗 ?你有什么主意吗 ?

非常感谢提前! :)

2 回答

  • 0

    traefik端口应该是容器的http端口,而不是主机上的已发布端口 . 它通过docker网络进行通信,因此发布端口是不必要的,并且目标只是使用反向代理发布单个端口来访问所有容器 .

    简而言之,您需要:

    traefik.port=80
    
  • 14

    traefik.docker.network 也必须是完全限定的网络名称 . 外部定义或前缀为堆栈名称 .

    您也可以使用 docker.network=traefik-network 定义默认网络,这意味着您不必将标签添加到每个容器 .

相关问题