我已经安装了 Traefik v2.x 反向代理。它接收来自外部应用程序的请求并将它们传递到 SOAP API 后端。 SOAP 服务以 WSDL 文件进行响应。在此 WSDL (XML) 文件(在 HTTP 响应正文中)中,我有一个不正确的字符串(URL),我想在 Traefik 将响应发送回调用应用程序之前重写它。
我知道有一个模块可以使用 nginx ( http_sub_module ) 来做到这一点,但是可以使用 Traefik 来做到这一点吗?我还没有找到适合我需求的中间件。
感谢您的宝贵时间和您的回答。
最佳答案
在最新版本的 Traefik(例如 2.9.x)中,现在无需注册 Traefik Pilot 程序即可访问插件存储库。
因此,您可以按照 Traefik plugin installation guide 自由添加插件.
符合我需求的插件是 rewriteBody plugin .
要使用它,您必须更新静态配置,添加以下内容:
experimental:
plugins:
rewritebody:
moduleName: "github.com/traefik/plugin-rewritebody"
version: "v0.3.1"
您可以在动态配置中使用它,例如
http:
routers:
test-router:
entryPoints:
- "websecure"
rule: "Host(`your.domain.org`) && PathPrefix(`/path`)"
middlewares:
- test-rewritebody
service: test
tls: {}
middlewares:
test-rewritebody:
plugin:
rewritebody:
lastModified: "true"
rewrites:
- regex: foo
replacement: bar
这非常有效!
关于http - 使用 Traefik 替换 HTTP 响应正文中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72218521/