首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Traefik重定向

Traefik重定向
EN

Stack Overflow用户
提问于 2022-03-02 02:08:45
回答 1查看 443关注 0票数 0

我试图在Traefik的文件提供程序中实现一个基本的重定向。我希望有以下几点:

代码语言:javascript
运行
复制
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

以下是我的尝试:

代码语言:javascript
运行
复制
http:
  middlewares:
    redirect-foobar:
      redirectRegex:
        permanent: true
        regex: "^https?://(www\\.)?example\\.com/foobar(/?.*)"
        replacement: "https://foobar.example.com${2}"
  routers:
    catch-foobar:
      middlewares:
        - redirect-foobar
      rule: Host(`example.com`) || Host(`www.example.com`)
      service: noop@internal

但当我尝试的时候,我得到的是:

代码语言:javascript
运行
复制
$ 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 =)
代码语言:javascript
运行
复制
$ 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

编辑:修正了regex,但是https大小写仍然有问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-03 00:35:22

Traefik社区论坛的人帮了我。原来路由器没有tls配置。正确的配置如下所示:

代码语言:javascript
运行
复制
http:
  middlewares:
    redirect-foobar:
      redirectRegex:
        permanent: true
        regex: "^https?://(www\\.)?example\\.com/foobar(/?.*)"
        replacement: "https://foobar.example.com${2}"
  routers:
    catch-foobar:
      middlewares:
        - redirect-foobar
      rule: Host(`example.com`) || Host(`www.example.com`)
      service: noop@internal
      tls:  # here
        certResolver: default

其中default是在我的traefik.yml中定义的证书解析器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71316670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档