traefik中的nginx`sexy_redirect`(重定向而不更改url)

时间:2018-04-09 19:37:43

标签: nginx traefik

如果可能的话,基本上如何在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实现?

1 个答案:

答案 0 :(得分:0)

在Traefik中,该重定向标签用于与客户端进行交互(将浏览器发送到其他位置)

我仍在尝试找出proxy_redirect的确切替代品。根据{{​​3}},此指令:

  

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

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

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

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

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

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

相关问题