首页 文章

如何从zuul路由中排除或忽略特殊路径或路由

提问于
浏览
6

是否可以从Zuul路由中排除路径或匹配器?

目标是

  • 对/ contracts / **的所有请求都将路由到contract.example.com

  • 对/ audit / **的所有请求都将路由到audit.example.com

  • 对/ heartbeat / **或/ sso / **的所有请求都直接从zuul提供 .

  • 所有其他请求(/ **)都路由到html.example.com

我有这样的配置:

zuul:
    routes:
        contract:
            path: /contracts/**
            url: http://contracts.example.com:8080/api
        audit:
            path: /audits/**
            url: http://audit.example.com:8080
        html:
            path: /**
            url: http://html.example.com:80

现在的问题是如何定义/ heartbeat和/ sso没有被zuul路由到html.example.com?

我正在使用Spring Boot及其AutoConfiguration .

2 回答

  • 11

    有一个名为ignored-patterns的配置属性 . 通过这种方式,可以定义匹配器以从路由中排除路由 .

    zuul:
        ignoredPatterns:
            - /heartbeat/**
            - /sso/**
        routes:
            contract:
                path: /contracts/**
                url: http://contracts.example.com:8080/api
            audit:
                path: /audits/**
                url: http://audit.example.com:8080
            html:
                path: /**
                url: http://html.example.com:80
    
  • 3

    Brixton.SR6 开始,应在 application.yml 文件中定义ignoredPattern属性 . 它应该定义如下:

    zuul:
    ignoredPatterns: /heartbeat/**, /sso/**
    routes:
        contract:
            path: /contracts/**
            url: http://contracts.example.com:8080/api
    

相关问题