Traefik 重定向
Traefik redirections
我正在尝试在 Traefik 的文件提供程序中实现基本的重定向。我会
像下面这样:
http://example.com/foobar -> https://foobar.example.com
http://www.example.com/foobar -> https://foobar.example.com
https://example.com/foobar -> https://foobar.example.com
https://www.example.com/foobar -> https://foobar.example.com
这是我的尝试:
http:
middlewares:
redirect-foobar:
redirectRegex:
permanent: true
regex: "^https?://(www\.)?example\.com/foobar(/?.*)"
replacement: "https://foobar.example.com"
routers:
catch-foobar:
middlewares:
- redirect-foobar
rule: Host(`example.com`) || Host(`www.example.com`)
service: noop@internal
但是当我尝试时,我得到的是:
$ curl -I http://www.example.com/foobar
HTTP/1.1 308 Permanent Redirect
Location: https://foobar.example.com
Date: Wed, 02 Mar 2022 02:12:48 GMT
Content-Length: 18
Content-Type: text/plain; charset=utf-8
# That's good =)
$ curl -I https://www.example.com/foobar
HTTP/2 404
content-type: text/plain; charset=utf-8
x-content-type-options: nosniff
content-length: 19
date: Wed, 02 Mar 2022 02:05:22 GMT
# Does that mean the request didn't even make it to the catch-foobar router?
我做错了什么?任何帮助将不胜感激。
谢谢,
C
编辑:修复了正则表达式,但 https 大小写仍然有问题
Traefik 社区论坛的人们帮助了我。原来路由器没有tls配置。正确的配置如下所示:
http:
middlewares:
redirect-foobar:
redirectRegex:
permanent: true
regex: "^https?://(www\.)?example\.com/foobar(/?.*)"
replacement: "https://foobar.example.com"
routers:
catch-foobar:
middlewares:
- redirect-foobar
rule: Host(`example.com`) || Host(`www.example.com`)
service: noop@internal
tls: # here
certResolver: default
其中 default
是我的 traefik.yml
中定义的证书解析器。
我正在尝试在 Traefik 的文件提供程序中实现基本的重定向。我会 像下面这样:
http://example.com/foobar -> https://foobar.example.com
http://www.example.com/foobar -> https://foobar.example.com
https://example.com/foobar -> https://foobar.example.com
https://www.example.com/foobar -> https://foobar.example.com
这是我的尝试:
http:
middlewares:
redirect-foobar:
redirectRegex:
permanent: true
regex: "^https?://(www\.)?example\.com/foobar(/?.*)"
replacement: "https://foobar.example.com"
routers:
catch-foobar:
middlewares:
- redirect-foobar
rule: Host(`example.com`) || Host(`www.example.com`)
service: noop@internal
但是当我尝试时,我得到的是:
$ curl -I http://www.example.com/foobar
HTTP/1.1 308 Permanent Redirect
Location: https://foobar.example.com
Date: Wed, 02 Mar 2022 02:12:48 GMT
Content-Length: 18
Content-Type: text/plain; charset=utf-8
# That's good =)
$ curl -I https://www.example.com/foobar
HTTP/2 404
content-type: text/plain; charset=utf-8
x-content-type-options: nosniff
content-length: 19
date: Wed, 02 Mar 2022 02:05:22 GMT
# Does that mean the request didn't even make it to the catch-foobar router?
我做错了什么?任何帮助将不胜感激。
谢谢,
C
编辑:修复了正则表达式,但 https 大小写仍然有问题
Traefik 社区论坛的人们帮助了我。原来路由器没有tls配置。正确的配置如下所示:
http:
middlewares:
redirect-foobar:
redirectRegex:
permanent: true
regex: "^https?://(www\.)?example\.com/foobar(/?.*)"
replacement: "https://foobar.example.com"
routers:
catch-foobar:
middlewares:
- redirect-foobar
rule: Host(`example.com`) || Host(`www.example.com`)
service: noop@internal
tls: # here
certResolver: default
其中 default
是我的 traefik.yml
中定义的证书解析器。