Traefik 不会在内部将传入的 443 映射到端口 80

Traeffik does not map incoming 443 to port 80 internally

我们的问题是来自 https 入口点的流量(可能)被转发到具有错误端口的后端。访问 http 入口点按预期工作:流量在服务器 1 2 3 之间进行负载平衡。使用 https 入口点时,我们得到 404 页面未找到。 TLS 一切正常,连接安全,但看起来 traefik 没有将后端服务器的端口更改为 :80。

我们确实让我们通过 traefik 加密,这看起来不错。

这是我们开始流量的方式:

docker run -d -p 443:443 -p 80:80 -v /home/pi/lbtest/traefik/traefik.toml:/traefik.toml -v /home/pi/lbtest/traefik/acme.json:/acme.json traefik

这是我们的 traefik.toml

debug = true

[file]

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

[frontends]
  [frontends.lbtest]
  backend = "lbtest"
    [frontends.lbtest.routes.route0]
    rule = "Host:xxx.gotdns.ch"

[backends]
  [backends.lbtest]
    [backends.lbtest.servers.server1]
    url = "http://192.168.178.81:80"
    [backends.lbtest.servers.server2]
    url = "http://192.168.178.49:80"
    [backends.lbtest.servers.server3]
    url= "http://192.168.178.64:80"


[acme]
email = "xxx@xxx.eu.com"
storageFile = "acme.json"
acmeLogging = true
entryPoint = "https"
onHostRule = true

[acme.httpChallenge]
entryPoint = "http"

[[acme.domains]]
main = "xxx.gotdns.ch"

为什么 http://xxx.gotdns.ch work - it loadbalances between server 1 2 3 - but not for https://xxx.gotdns.ch。有什么想法吗?

您配置中的 defaultEntryPoints 字段有问题:

debug = true

defaultEntryPoints = ["http", "https"] # <-- move the field here

[file]

[entryPoints]
  [entryPoints.http]
  address = ":80"
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

[frontends]
  [frontends.lbtest]
  backend = "lbtest"
    [frontends.lbtest.routes.route0]
    rule = "Host:xxx.gotdns.ch"

[backends]
  [backends.lbtest]
    [backends.lbtest.servers.server1]
    url = "http://192.168.178.81:80"
    [backends.lbtest.servers.server2]
    url = "http://192.168.178.49:80"
    [backends.lbtest.servers.server3]
    url= "http://192.168.178.64:80"


[acme]
email = "xxx@xxx.eu.com"
storageFile = "acme.json"
acmeLogging = true
entryPoint = "https"
onHostRule = true

[acme.httpChallenge]
entryPoint = "http"

[[acme.domains]]
main = "xxx.gotdns.ch"

我建议你这样写你的配置:

debug = true

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

[acme]
email = "xxx@xxx.eu.com"
storageFile = "acme.json"
acmeLogging = true
entryPoint = "https"
onHostRule = true

[acme.httpChallenge]
entryPoint = "http"

[[acme.domains]]
main = "xxx.gotdns.ch"

[file]
[frontends]
  [frontends.lbtest]
  backend = "lbtest"
    [frontends.lbtest.routes.route0]
    rule = "Host:xxx.gotdns.ch"

[backends]
  [backends.lbtest]
    [backends.lbtest.servers.server1]
    url = "http://192.168.178.81:80"
    [backends.lbtest.servers.server2]
    url = "http://192.168.178.49:80"
    [backends.lbtest.servers.server3]
    url= "http://192.168.178.64:80"