日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Zuul的各种姿势

發布時間:2024/4/13 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Zuul的各种姿势 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Zuul Http Clienthttps://cloud.spring.io/spring-cloud-netflix/reference/html/#_zuul_http_clientZuul是使用Apache的HTTP Client,他以前用的是Ribbon Rest Client,在新的版本是用的HTTP Client,如果你還是想用RestClient呢,或者我想使用okhttp3,也是可以的,如果你想用RestClient,可以使用ribbon.restclient.enabled=true這個屬性,如果你想用okhttp3,就用okhttp3.OkHttpClient這個屬性,The default HTTP client used by Zuul is now backed by the Apache HTTP Client instead of the deprecated Ribbon RestClient. To use RestClient or okhttp3.OkHttpClient, set ribbon.restclient.enabled=true or ribbon.okhttp.enabled=true, respectively. If you would like to customize the Apache HTTP client or the OK HTTP client, provide a bean of type ClosableHttpClient or OkHttpClient.我們來看Cookies and Sensitive Headerszuul:routes:users:path: /myusers/**sensitiveHeaders: Cookie,Set-Cookie,Authorizationurl: https://downstreamsensitiveHeaders是什么意思,有一些敏感的HTTP頭,我可能不想讓他傳到Zuul后端的微服務,或者我不想讓他傳到瀏覽器上來,那這個時候我就可以用這個屬性去設置,sensitiveHeaders,看一下他的默認值org.springframework.cloud.netflix.zuul.filters.ZuulProperties/*** List of sensitive headers that are not passed to downstream requests. Defaults to a* "safe" set of headers that commonly contain user credentials. It's OK to remove* those from the list if the downstream service is part of the same system as the* proxy, so they are sharing authentication data. If using a physical URL outside* your own domain, then generally it would be a bad idea to leak user credentials.*/ private Set<String> sensitiveHeaders = new LinkedHashSet<>(Arrays.asList("Cookie", "Set-Cookie", "Authorization"));這段注釋很重要,里面提到了一個downstream,我們的請求是不是從用戶,經過瀏覽器,然后經過zuul,這是后端微服務,他認為數據像一個流水一樣,瀏覽器,zuul,后端微服務,downstream指的是什么,對于一個request downstream,他默認的是一個安全的頭的集合,你可以移掉"Cookie", "Set-Cookie", "Authorization"三個里面的一個,如果你正在使用外部的物理URL,一般來說他不該這么玩,sensitiveHeaders他的作用是什么呢,我讓zuul不傳播,zuul會反向代理,我把這些header攔下來了,不傳到下游的服務里面去,同理還有ignoreHeaders,sensitiveHeaders會加到Ignored Headers里面去https://github.com/spring-cloud/spring-cloud-netflix/issues/1487Understanding zuul.ignoredHeaders and zuul.ignoreSecurityHeaders #1487假設設置Setting zuul.ignoredHeaders = Header1, Header2,"Header1, Header2"就不會傳入到微服務里面去了,就被zuul攔截掉了,默認情況下它是空的,默認情況下Ignored Headers它是空的,假設 Spring SecurityPragma,Cache-Control,X-Frame-Options,X-Content-Type-Options,X-XSS-Protection,Expires就是這些,Otherwise, they are initialized to a set of well known “security” headers (for example, involving caching) as specified by Spring Security./*** Flag to say that SECURITY_HEADERS are added to ignored headers if spring security is on the classpath.* By setting ignoreSecurityHeaders to false we can switch off this default behaviour. This should be used together with* disabling the default spring security headers* see https://docs.spring.io/spring-security/site/docs/current/reference/html/headers.html#default-security-headers*/ private boolean ignoreSecurityHeaders = true;Routes Endpointhttps://cloud.spring.io/spring-cloud-netflix/reference/html/#_routes_endpointlocalhost:8040/routes可以看到zull代理微服務的路徑localhost:8040/microservice-simple-provider-user/simple/1There was an unexpected error (type=Unauthorized, status=401).management.security.enabled=falselocalhost:8040/routes{"/microservice-simple-provider-user/**":"microservice-simple-provider-user"}https://cloud.spring.io/spring-cloud-netflix/reference/html/#_strangulation_patterns_and_local_forwardsStrangulation Patterns and Local Forwards先說一下什么是校驗者模式,StranglerApplication martinfolwerhttps://martinfowler.com/bliki/StranglerFigApplication.html一個很重的單體架構,單體服務,我想把它改造成微服務,我可能一口氣做不到,我可以慢慢的把它轉變成一個微服務架構zuul:routes:first:path: /first/**url: https://first.example.comsecond:path: /second/**url: forward:/secondthird:path: /third/**url: forward:/3rdlegacy:path: /**url: https://legacy.example.com 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%nmanagement.security.enabled=false

?

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的Zuul的各种姿势的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。