Magento 2:traefik 反向代理背后的重定向太多

Magento 2: Too many redirects behind traefik reverse-proxy

在我的网络服务器和 Docker 应用程序前面,我是 运行 Traefik 来处理负载平衡和反向代理。在这种特定情况下,Magento 2 在与 Traefik 主机位于同一私有网络中的另一台主机上 运行。

  1. Traefik: 192.168.1.30
  2. Magento: 192.168.1.224

流量通过端口 80/443 进入防火墙并转发到 Traefik,Traefik 根据域名转发请求(在本例中 exampleshop.com)。

我的 Traefik 配置如下所示:

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

[backends]
  [backends.backend-exampleshop]
    [backends.backend-exampleshop.servers.server1]
    url = "http://192.168.1.224:80
    passHostHeader = true
[frontends]
  [frontends.exampleshop]
  backend = "backend-exampleshop"
    [frontends.exampleshop.routes.hostname]
    rule = "Host:exampleshop.com"

对于常规网站,上述配置总是按预期工作(有效的 HTTPS 连接和有效的 Let's Encrypt 证书)但在这个 Magento 2 案例中它导致:

ERR_TOO_MANY_REDIRECTS

因此我无法访问我的主页和我的管理页面。查看数据库记录,我将我的不安全配置为安全 URL 和 https://exampleshop.com 以避免重定向错误。

Apache 在端口 80 上监听良好,当直接联系(通过更改我的主机文件)时,页面通过 HTTP 显示得很好。

我在这里错过了什么?

我假设192.168.1.224是安装Traefik的IP(本地)

entryPoints.http : address = ":80" == address = "0.0.0.0:80"

  • https//exampleshop.com
    • entryPoints.https(因为 https == 端口 443)
    • frontends.example1(因为rule = "Host:exampleshop.com"
    • backend-example1: server = "http://192.168.1.224:80"
    • entryPoints.http 因为 :80 == http://192.168.1.224:80
    • 重定向到 entryPoints.https
    • 等等

尝试更改本地应用程序的端口。

  • 下面的代码解决了这个问题 OR
  • 在您的 Traefik 上启用 ACME 并将 Cloudflare 上的 SSL 模式切换为 Full(如果启用)
[entryPoints.http.redirect]
    entryPoint = "https"

实际上,配置是完全有效的,但 Cloudflare 的 crypto/SSL 设置被设置为 Flexible 而不是 Full;导致循环。

我也 运行 加入了这个,但是我发现我必须添加这个:

ingress.kubernetes.io/ssl-proxy-headers: "X-Forwarded-Proto: https"

在我们的 kubernetes 入口清单中,它修复了它。