【发布时间】:2015-11-23 22:12:46
【问题描述】:
我已经设置了一个带有几个 Spring Cloud 服务(配置、服务注册表和 Zuul)的本地环境。代理使用默认映射正确地公开服务:
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/api-proxy/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/service-discovery/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/config-service/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/circuitbreaker-collector/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/circuitbreaker-dashboard/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
我看到的问题是,当我转到 http://localhost/service-discovery/ 时,我看到了 Eureka 仪表板,但没有加载相关的静态资源。浏览器显示如下错误:
http://localhost/eureka/css/wro.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/eureka/js/wro.js Failed to load resource: the server responded with a status of 404 (Not Found)
service-discovery:223 Uncaught ReferenceError: $ is not defined
http://localhost/eureka/css/wro.css Failed to load resource: the server responded with a status of 404 (Not Found)
有没有办法解决这个问题?据我所知,Eureka 仪表板在加载资源时没有使用相对路径,而是假设应用程序已部署到根 servlet 上下文。
更新 我意识到我错过了代表问题。我评论了这个帖子,但我想我会把它带到主帖。问题是 Zuul 代表客户端发出后端请求。当 Zuul 发出该请求时,HTML 响应包含相对于为 Eureka 配置的上下文路径的 URL。通常,代理服务将通过重写响应中找到的任何 URL 来管理此问题,以具有关于代理如何公开它的正确基本上下文。 Zuul 有这样的东西吗?
更改主题以更好地描述问题。
【问题讨论】:
-
是的,你可以改变eureka服务器的上下文,告诉zuul不要去掉前缀。但我质疑您为什么希望通过 zuul 提供仪表板。
-
我理解在正常情况下这不会通过 Zuul 暴露出来。我只是在玩弄使用 Zuul 代理的服务之间的连接。
-
对于其他代理类型服务,通常管理的方式是重写来自后端服务的响应中的 URL,以便将来自 Zuul 的上下文应用于这些 URL。这是 Zuul 提供的东西,是使用 Zuul 时推荐的方法吗?
-
看起来这个问题是在 Spring Cloud Zuul 的上下文中提出的:github.com/spring-cloud/spring-cloud-netflix/issues/8
标签: spring-cloud netflix-eureka netflix-zuul