[英]Spring Cloud Gateway : disable default routes
I'm using spring cloud to manage my microservices. 我正在使用Spring Cloud管理我的微服务。
For security reasons, for one specific microservice (name it ms_secure), I want to use custom route choose a specific microservice version depending on client IP. 出于安全原因,对于一个特定的微服务(命名为ms_secure),我想使用自定义路由,根据客户端IP选择特定的微服务版本。
My gateway config looks like this: 我的网关配置如下所示:
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
routes:
- id: ms_secure_v1
uri: lb://ms_secure_v1
predicates:
- Path=/ms_secure/**
filters:
- RewritePath=/ms_secure/(?<segment>.*), /$\{segment}
- name: <my filter>
args:
xForwardedForHeaderName: X-Forwarded-For
hosts:
- <IP1>
- <IP2>
- id: ms_secure
uri: lb://ms_secure_v2
predicates:
- Path=/ms_secure/**
filters:
- RewritePath=/ms_secure/(?<segment>.*), /$\{segment}
- name: <my filter>
args:
xForwardedForHeaderName: X-Forwarded-For
hosts:
- <IP3>
- <IP4>
When when requesting /ms_secure: 当请求/ ms_secure时:
My problem is that all my clients will also be able to access directly ms_secure_v1 or ms_secure_v2 by using the default routes: 我的问题是,所有我的客户端也将能够通过使用默认路由直接访问ms_secure_v1或ms_secure_v2:
http:///ms_secure_v1/...
http:/// ms_secure_v1 / ...
http:///ms_secure_v2/...
http:/// ms_secure_v2 / ...
I tried to disable these routes by using SetStatus GatewayFilter: 我试图通过使用SetStatus GatewayFilter禁用这些路由:
- id: setstatusstring_route
uri: lb://ms-gateway
predicates:
- Path=/ms_secure_v**
filters:
- SetStatus=403
But this route is not matched. 但是这条路线不匹配。
Is there a way to disable these default routes in spring gateway? 有没有办法在Spring Gateway中禁用这些默认路由?
The following creates routes in gateway based on services registered: 以下内容基于注册的服务在网关中创建路由:
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
Set it to false (which is the default), if you don't want this. 如果您不想这样做,请将其设置为false(这是默认设置)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.