After
判断时间在After
配置的时间之后规则才生效
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- After=2017-01-20T17:42:47.789-07:00[America/Denver]
Before
判断在Before
之前路由配置才生效
spring:
cloud:
gateway:
routes:
- id: before_route
uri: https://example.org
predicates:
- Before=2017-01-20T17:42:47.789-07:00[America/Denver]
Between
在时间之内规则生效
spring:
cloud:
gateway:
routes:
- id: between_route
uri: https://example.org
predicates:
- Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]
Cookie
带cookie,名字和正则表达式
cookie中需要带有key并且符合value的正则表达式。不带cookie会404
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://example.org
predicates:
- Cookie=key, value
Header
请求头文件中带key的名称时 X-Request-Id 值是正则表达式\d+(数字)
其他信息自己添加
spring:
cloud:
gateway:
routes:
- id: header_route
uri: https://example.org
predicates:
- Header=X-Request-Id, \d+
Host
主机是yumbo.top或者huashengshu.top的子域名的规则生效,如果不带这个信息,则会返回404
头文件中设置 Host
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Host=**.yumbo.top,**.huashengshu.top
Method
请求方法要是配置中设置的GET或者POST路由才会生效
spring:
cloud:
gateway:
routes:
- id: method_route
uri: https://example.org
predicates:
- Method=GET,POST
Path
请求路径要符合Path设置的规则路由才生效
spring:
cloud:
gateway:
routes:
- id: path_route
uri: https://example.org
predicates:
- Path=/red/{segment},/blue/{segment}
Query
请求参数要包含green参数路由才生效
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=green
RemoteAddr
如果请求的远程地址是192.168.1.10,则此路由匹配。
spring:
cloud:
gateway:
routes:
- id: remoteaddr_route
uri: https://example.org
predicates:
- RemoteAddr=192.168.1.1/24
Weight
这条路径将把80%的流量转发到weighthigh.org,并将20%的流量转发到weighlow.org
权重路由,按照权重分流量
spring:
cloud:
gateway:
routes:
- id: weight_high
uri: https://weighthigh.org
predicates:
- Weight=group1, 8
- id: weight_low
uri: https://weightlow.org
predicates:
- Weight=group1, 2