【问题标题】:nginx `proxy_redirect` in traefik (redirect without changing url)traefik 中的 nginx `proxy_redirect`(重定向而不更改 url)
【发布时间】:2018-04-09 19:37:42
【问题描述】:

如果可能的话,基本上这在 traefik 中会是什么样子:

location  /blog/ {
    proxy_pass https://blog.example.com/;
    proxy_redirect https://blog.example.com/ https://www.example.com/blog/;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host blog.example.com;
} 

我试过了,我的 docker-compose 中的这个配置:

- 'traefik.frontend.redirect.regex=^https://example.com/blog/(.*)$$'
- 'traefik.frontend.redirect.replacement=https://blog.example.com/$$1'

这确实有效,但它只是重定向到https://blog.example.com,我想保留原始网址https://example.com/blog/ 并显示来自https://blog.example.com 的内容。

可以用traefik实现吗?

【问题讨论】:

    标签: nginx traefik


    【解决方案1】:

    在 Traefik 中,该重定向标签用于与客户端交互(将您的浏览器发送到另一个位置)

    我仍在尝试找出 proxy_redirect 的确切替代品。根据Nginx docs,该指令:

    设置应在代理服务器响应的“Location”和“Refresh”标头字段中更改的文本。

    所以在 docker-compose.yaml 中,这两个标头字段可以这样放置:

    labels:
      - "traefik.frontend.headers.customResponseHeaders=Location:value1||Refresh:value1"
    

    但我不确定如何用正则表达式替换它们。也许还有一种更“traefikal”的方法。

    我知道这不是一个真正的答案,但由于我的低分,我无法发表评论。

    我在为 Traefik SSL 背后的 Jenkins 寻找解决方案时发现了您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-02
      • 1970-01-01
      • 2013-02-25
      • 2018-11-11
      • 2015-04-02
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多