Zuul最核心的类就是ZuulServlet。使用springcloud的zuul网关,配置routes的规则时,对于routes类型的系统filter有三种:RibbonRoutingFilter、SimpleHostRoutingFilter、SendForwardFilter。
对于使用yaml配置zuul的routes规则介绍,直接看配置文件及注释:
zuul:
##敏感头配置为空之后,所有head内容透传给后端服务,即后端服务也可以获取到请求头信息,一般不配置,因为网关就把头部信息的逻辑包了
sensitive-headers:
#配置自定义路由规则,不配置routes,使用服务名访问的话默认走RibbonRoutingFilter
# 不配置routes 使用 http://localhost:9100/service-sms/send/msg可以访问
routes:
##配置path+url 走SimpleHostRoutingFilter 跳转到指定的 URL 中
# 使用 http://localhost:9100/mytttttt/send/msg 可以访问
##provider1这个名称随便写
provider1:
path: /mytttttt/**
url: http://localhost:8001/
#配置path+servcieId,走默认的RibbonRoutingFilter
# 使用 http://localhost:9100/mysuibian/send/msg 可以访问
provider2:
path: /mysuibian/**
serviceId: service-sms
#配置path+servcieId,可以配置多个 使用 http://localhost:9100/suibian/send/msg 可以访问
provider3:
path: /suibian/**
serviceId: service-sms
# 配置ignored-patterns之后 使用 http://localhost:9100/suibian/send/msg 不可以访问,其他的 /mytttttt/send/msg,/mysuibian/send/msg,/service-sms/send/msg都可以访问
ignored-patterns: /**/suibian/**
#配置prefix之后,所有的请求都需要加上/api才能访问,/mytttttt/send/msg,/mysuibian/send/msg,/service-sms/send/msg无法访问,需要使用/api/mytttttt/send/msg,/api/mysuibian/send/msg,/api/service-sms/send/msg进行访问
prefix: /api
环境说明:
我的网关服务端口是9100.
我的后端服务在eureka中的application.name是service-sms, 这个服务的端口是8001,这个服务提供了一个/send/msg接口