Traefik v2 http 404 重定向到外部

发布于 2025-01-12 06:42:12 字数 997 浏览 0 评论 0原文

一段时间以来,我无法解决看似简单的问题:

如何捕获未知路由器并将其重定向到外部域而不使用另一个反向代理(例如 nginx,如所述 这里)?

traefik:
    ...
    labels:
      - "traefik.enable=true"

      - "traefik.http.routers.http_catchall.rule=HostRegexp(`{any:.+}`)"
      - "traefik.http.routers.http_catchall.priority=1"
      - "traefik.http.routers.http_catchall.entrypoints=unsecure"
      - "traefik.http.routers.http_catchall.middlewares=error-catch,https-redirect"

      - "traefik.http.middlewares.error-catch.errors.status=404"
      - "traefik.http.middlewares.error-catch.errors.service=error-redirect"
      - "traefik.http.middlewares.error-catch.errors.query=/"

      - "traefik.http.middlewares.https-redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.https-redirect.redirectscheme.permanent=true"

      # now how to use "error-redirect" service to forward to eg https://google.com

有什么想法吗?

For some time now I can't wrap my head around seemingly simple problem:

How to catch unknown routers and redirect it to external domain without using another reverse proxy (eg nginx as described here)?

traefik:
    ...
    labels:
      - "traefik.enable=true"

      - "traefik.http.routers.http_catchall.rule=HostRegexp(`{any:.+}`)"
      - "traefik.http.routers.http_catchall.priority=1"
      - "traefik.http.routers.http_catchall.entrypoints=unsecure"
      - "traefik.http.routers.http_catchall.middlewares=error-catch,https-redirect"

      - "traefik.http.middlewares.error-catch.errors.status=404"
      - "traefik.http.middlewares.error-catch.errors.service=error-redirect"
      - "traefik.http.middlewares.error-catch.errors.query=/"

      - "traefik.http.middlewares.https-redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.https-redirect.redirectscheme.permanent=true"

      # now how to use "error-redirect" service to forward to eg https://google.com

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2025-01-19 06:42:12

您可以添加一个 文件提供程序,在其中为外部 URL 定义服务。

http:
  services:
    google:
      loadBalancer:
        servers:
        - url: http://google.com

并像这样在中间件中分配该服务

- "traefik.http.middlewares.error-catch.errors.service=google@file"

You can add a file provider in which you define a service for an external url.

http:
  services:
    google:
      loadBalancer:
        servers:
        - url: http://google.com

and assign that service in the middleware like so

- "traefik.http.middlewares.error-catch.errors.service=google@file"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文