Traefik前端重定向不起作用

时间:2018-04-30 05:55:30

标签: traefik

嘿,我正在尝试捕获所有请求到子域,没有匹配的rool并将它们重定向到https://localhost:8000,没有子域和郊区。但是没有重定向,我只是从后端得到响应。

[file]
  [frontends]
    [frontends.homeRedirect]
      entryPoints = ["https"]
      priority = 1
      backend = "homeRedirect"
      [frontends.homeRedirect.routes.everything]
        rule = "PathPrefix:/"
      [frontends.homeRedirect.headers]
        SSLRedirect = true
      [frontends.homeRedirect.redirect]
        regex = "(.*)"
        replacement = "https://localhost:8000"
  [backends]
      [backends.homeRedirect]
        [backends.homeRedirect.servers]
          [backends.homeRedirect.servers.server0]
            url = "http://frontend:80"

我的档案有问题吗?

1 个答案:

答案 0 :(得分:1)

在这种情况下,入口点上的重定向更合适:

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    regex = "^http://subdomain.mydomain/(.*)"
    replacement = "http://myotherdomain/$1"

https://docs.traefik.io/v1.5/configuration/entrypoints/#rewriting-url

Traefik容器内的

localhost是容器而不是真正的机器。