200801-SpringCloud-Gateway地址重写

SpringCloud Gateway地址重写

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server:
port: 8080 #端口
spring:
application:
name: api-gateway-server #服务名称
redis:
host: localhost
pool: 6379
database: 0
cloud: #配置SpringCloudGateway的路由
gateway:
routes:
- id: product-service #保持唯一
uri: lb://service-product #lb://根据微服务名称从注册中心拉取服务请求路径
predicates:
- Path=/product-service/** #将当前请求转发到http://127.0.0.1:9001/product/1
filters: #配置路由过滤器,将当前请求http://127.0.0.1:9001/product-service/product/1 --》 http://127.0.0.1:9001/product/1
- RewritePath=/product-service/(?<segment>.*), /$\{segment} #路径重写的过滤器,在yml中$写为$\
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×