将多个路径重定向到外部URL

时间:2018-06-20 07:48:05

标签: traefik rancher

我在使用traefik将多个路径重定向到多个目标时遇到问题。

由于软件的遗留原因,我不得不将应用程序后面的某些路径重定向到外部URL。 我的应用程序正在rancher中运行,我正在使用rancher标签来配置traefik:

traefik.enable: 'true'
traefik.app.backend: app
traefik.app.frontend.redirect.entryPoint: https
traefik.app.frontend.rule: 'Host: app.url'
traefik.app.protocol: http
traefik.app.port: '8080'
traefik.support.backend: support
traefik.support.protocol: https
traefik.support.frontend.redirect.regex: ^https?://app.url/support/(.*)
traefik.support.frontend.redirect.replacement: https://other.support.url    
traefik.support.port: '8080'

但是https://app.url/support没有重定向到https://other.support.url,并且出现404错误。

如果我只有要重定向的URL,则可以在https入口点的入口点级别添加重定向。 但是像我建议入口点不支持多个重定向。

[entryPoints.https]
 address = ":443"
 [entryPoints.https.redirect]
  regex = "^https://app.url/support"
  replacement = "https://other.support.url"

如何使用最新的traefik 1.6.4和Rancher 1.6.x实现此目的。 还是有可能?

我不想只使用像nginx这样的代理来进行重定向,这增加了很多麻烦,而且我发现带有标签的配置非常舒适和透明。

有任何想法吗?

1 个答案:

答案 0 :(得分:1)

您可以将规则移到前端。由于前端似乎需要定义一个后端,因此即使永不调用它也只需对其进行定义。

[backends]
  [backends.fake]
    [backends.fake.servers.s1]
      url="http://1.2.3.4"

[frontends]
[frontends.r1]
  backend = "fake"
  [frontends.r1.redirect]
    regex = "^http://foo.bar/(.*)"
    replacement = "http://mydomain1/$1"
    permanent = false
[frontends.r2]
  backend = "fake"
  [frontends.r2.redirect]
    regex = "^http://bar.blech/(.*)"
    replacement = "http://mydomain2/$1"
    permanent = false