Traefik 2 中间件适用于 https,但不适用于 http 入口点
Traefik 2 middleware is working on https, but not http entry points
我正在尝试设置一个路由来执行基本的 301 重定向,同时支持 HTTP 和 HTTPS 请求。预期结果是请求 http://subdom.domain.org or https://subdom.domain.org would receive a 301 and be forwarded to https://othersub.domain.org/route. Actual results is that https://subdom.domain.org 301's as expected, but http://subdom.domain.org 404。通过配置,您可以看到我已经尝试将两个提升到 HTTPS,希望规则可能会在那里被捕获,但是根据中间件的配置方式,我希望它在任何一种情况下都能正常工作。
这是我当前的配置:
http:
routers:
subdom.domain.org:
entryPoints:
- web
- web-secure
middlewares:
- https-redirect # I've tried with this on and off
- sudbdom-redirect
service: dummy
rule: Host(`subdom.domain.org`)
tls:
certResolver: letsEncryptResolver
middlewares:
https-redirect:
redirectScheme:
scheme: https
subdom-redirect:
redirectRegex:
regex: ".*"
replacement: "https://othersub.domain.org/route"
permanent: true
services:
dummy:
loadBalancer:
servers:
- url: localhost
我最初在为重定向匹配特定的正则表达式模式时遇到了问题,但我意识到我根本不需要限定模式的范围,因为我正在为每个路由应用它,通配符匹配似乎很有效好吧。任何想法或建议表示赞赏。谢谢!
您应该尝试制作 2 个不同的路由器,一个用于 Web 入口点,您可以在其中执行重定向,第二个用于 redirectRegex,您可以在其中将您的应用程序重定向到不同的 url。
我正在尝试设置一个路由来执行基本的 301 重定向,同时支持 HTTP 和 HTTPS 请求。预期结果是请求 http://subdom.domain.org or https://subdom.domain.org would receive a 301 and be forwarded to https://othersub.domain.org/route. Actual results is that https://subdom.domain.org 301's as expected, but http://subdom.domain.org 404。通过配置,您可以看到我已经尝试将两个提升到 HTTPS,希望规则可能会在那里被捕获,但是根据中间件的配置方式,我希望它在任何一种情况下都能正常工作。
这是我当前的配置:
http:
routers:
subdom.domain.org:
entryPoints:
- web
- web-secure
middlewares:
- https-redirect # I've tried with this on and off
- sudbdom-redirect
service: dummy
rule: Host(`subdom.domain.org`)
tls:
certResolver: letsEncryptResolver
middlewares:
https-redirect:
redirectScheme:
scheme: https
subdom-redirect:
redirectRegex:
regex: ".*"
replacement: "https://othersub.domain.org/route"
permanent: true
services:
dummy:
loadBalancer:
servers:
- url: localhost
我最初在为重定向匹配特定的正则表达式模式时遇到了问题,但我意识到我根本不需要限定模式的范围,因为我正在为每个路由应用它,通配符匹配似乎很有效好吧。任何想法或建议表示赞赏。谢谢!
您应该尝试制作 2 个不同的路由器,一个用于 Web 入口点,您可以在其中执行重定向,第二个用于 redirectRegex,您可以在其中将您的应用程序重定向到不同的 url。