繁体   English   中英

使用Traefik将无效的子域重定向到特定的URL

[英]Redirect unvalid subdomain to specific URL with Traefik

我想使用traefik和Docker将无效的URL重定向到404错误

示例: https ://sub1.domain.com是traefik中引用的有效doamin,因此Traefik配置中不存在https://invalid.domain.com ,因此它将重定向到https:// error。 domain.com

我已经搜索了官方文档,发现的唯一一件事就是关于重定向,但是我不知道如何使用它们来实现我的目的。

您应该能够通过指定重定向和替换来做到这一点。 您还需要确保主机规则匹配任何子域。 这是docker-compose的配置:

services:
  traefik:
    # ...existing config
  sub1:
    # ...existing config
  error:
    # ...existing config
    labels:
      # Match all subdomains
      - traefik.frontend.rule=HostRegexp:{subdomain:[a-z]+}.domain.com
      - traefik.frontend.redirect.regex=^https?://(.*).domain.com
      - traefik.frontend.redirect.replacement=https://error.domain.com
      # Set priority to low number so matches after other rules
      - traefik.frontend.priority=1

如果您不介意域更改,而只是想显示一个错误,因为不需要traefik.frontend.redirect标签,这甚至会更加容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM