Zuul路由的strip-prefix与order
生活随笔
收集整理的這篇文章主要介紹了
Zuul路由的strip-prefix与order
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
因為目前的Spring Cloud的中文資料真的很少,stripPrefix,先來了解一下什么是Prefix,有一個叫zuul.prefix,zuul.prefix=/api用戶微服務和eureka已經起好了,看一下prefix是干嘛用的localhost:8040/api/microservice-simple-provider-user/simple/1前綴加上用戶微服務的id,微服務的路徑,prefix是干這個用的,stripPrefix是干嘛用的呢,選項默認是truezuul:routes:users:path: /myusers/**stripPrefix: falsezuul.strip-prefix=false
zuul.routes.user-route.stripPrefix=false剝掉前綴,設置成false,localhost:8040/api/microservice-simple-provider-user/simple/1這個路徑訪問不了是把api/這個去掉嗎localhost:8040/microservice-simple-provider-user/simple/1也訪問不了,我們借助日志loggin.level.com.netflix=debuglogging.level.com.learn=trace
logging.file=springboot.log
logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%n我們看他請求到了什么地址,我們訪問這個localhost:8040/api/microservice-simple-provider-user/simple/1看到請求到哪里zuul.prefix=/simple
zuul.stripPrefix=falselocalhost:8040/simple/microservice-simple-provider-user/simple/1也就是zuul代理的微服務的前綴,homePage是7900,有的微服務可能設置了context-path,localhost:7900/simple/1zuul.prefix=/simplelocalhost:8040/simple/microservice-simple-provider-user/simple/1zuul.prefix=/simple
zuul.stripPrefix=truehttps://github.com/spring-cloud/spring-cloud-netflix/issues/1365zuul.stripPrefix=false not work for all route? #1365zuul.stripPrefix specifically applies to zuul.prefix. zuul.routes.<route>.stripPrefix applies to zuul.routes.<route>.pathzuul:ignoredPatterns: /**/admin/**routes:users: /myusers/**忽略某些敏感的路徑zuul:ignoredServices: '*'routes:users: /myusers/**ignoredServices是粗粒度的忽略,他忽略的整個微服務https://blog.csdn.net/kevin_loving/article/details/80661259ignoredPatterns這個就可以做到更細粒度的忽略,忽略某些路徑,這樣配這里解釋的很好,https://cloud.spring.io/spring-cloud-netflix/reference/html/#_ignored_headersThe preceding example means that all calls (such as /myusers/101) are forwarded to /101 on the users service. However, calls including /admin/ do not resolve.zuul:ignoredPatterns: /**/admin/**routes:users: /myusers/**zuul:routes:users:path: /myusers/**legacy:path: /**users下是/myusers/**這么玩的,剩下的是/**這么玩的,叫legacy路由,你想利用rule的order,所謂的優先級了,現在優先級是什么,order是什么,你得用yaml,否則這個特性玩不起來If you were to use a properties file, the legacy path might end up in front of the users path, rendering the users path unreachable.所有的路由都講到這里
server.port=8040
spring.application.name=microservice-gateway-zuul-reg-exp
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
eureka.client.serviceUrl.defaultZone=http://admin:1234@10.40.8.152:8761/eureka
eureka.instance.appname=microservice-gateway-zuul-reg-exp
#zuul.prefix=/api
#zuul.routes.user-route.stripPrefix=false
zuul.prefix=/simple
zuul.stripPrefix=true
logging.level.com.learn=trace
logging.file=springboot.log
logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%n
?
總結
以上是生活随笔為你收集整理的Zuul路由的strip-prefix与order的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Zuul使用正则表达式指定路由规则
- 下一篇: Zuul的各种姿势