Spring Cloud Gateway 路由路径重写

举例

访问路径 http://internal-k8s.wyz.com/api/wyz/

变更为 http://internal-k8s.wyz.com/wyz/record/

有如下两种方法进行配置

生产环境用的方法一,方法二没有验证,如有问题感谢告知

方法一:

注意缩进

spring:
  cloud:
    gateway:
      routes:
        - id: wyz-route
          uri: http://internal-k8s.wyz.com
          predicates:
            - Path=/api/wyz/**
          filters:
            - RewritePath=/api/wyz/(?<segment>.*), /wyz/recode/$\{segment}
        #     - StripPrefix=3
        #     - PrefixPath=/wyz/recode

/api/wyz/是需要被替换
/wyz/recode/是替换后的URL

方法二

注意缩进

spring:
  cloud:
    gateway:
      routes:
        - id: wyz-route
          uri: http://internal-k8s.wyz.com
          predicates:
            - Path=/api/wyz/**
          filters:
            - StripPrefix=2
            - PrefixPath=/wyz/recode
上一篇:openstack中彻底删除计算节点的操作记录


下一篇:WPF 加载诡异的字体无法布局