问题

后台提示:
2020-08-19 18:56:21.440 WARN 15276 --- [nio-8210-exec-8] ashboardConfiguration$ProxyStreamServlet : Origin parameter: http://127.0.0.1:8010/hystrix.stream is not in the allowed list of proxy host names. If it should be allowed add it to hystrix.dashboard.proxyStreamAllowList.
解决
配置文件application.properties中添加白名单配置:
hystrix.dashboard.proxy-stream-allow-list=**
排错过程(原理)
-
日志文件中提示,需要配置
hystrix.dashboard.proxyStreamAllowList,但没有说明具体怎么配置,所以跟踪代码。 -
配置文件中按下键盘
ctrl点击配置项,跟踪进入Properties文件。proxyStreamAllowList配置项是一个String类型的数组,哪里用到了呢?继续跟踪。

-
查找
getProxyStreamAllowList()的调用。在getProxyStreamAllowList()方法中打断点,刷新页面。调用栈中发现isAllowedToProxy()方法调用了getProxyStreamAllowList()方法。

-
切换到
isAllowedToProxy()方法,阅读代码大概了解到是Hystrix Dashboard会通过proxyUrl解析到host部分,然后通过配置的proxyStreamAllowList判定是否允许被访问。这里我们可以看到pathMatcher.match(pattern, host)是判定的方法,可以猜测pattern的配置方式是host以.分隔配置的。为了确认这一项,继续进入match()方法。

-
match()方法调用了doMatch()方法,阅读代码时发现,代码中多次出现了**的判定,猜测**是通配的配置。将该配置配置在properties文件中,重启测试通过。(有兴趣的也可以阅读这段代码,然后得出结论,代码太长,我懒得读了)

本文详细解析了Hystrix Dashboard在配置白名单时遇到的问题及解决方案,通过修改application.properties文件中的hystrix.dashboard.proxy-stream-allow-list配置,解决了访问限制问题。
4717





