使用set server.context-path

时间:2015-08-21 09:06:10

标签: spring spring-boot spring-cloud spring-boot-actuator

在春季启动应用程序中我设置了例如server.context-path=/mymodule。这很方便,因为我不需要在/mymodule中反复重复@RequestMapping前缀。 此外,我希望将执行器端点组合在具有公共前缀的URL上,以便设置management.context-path=/actuator。 现在,执行器端点映射到/mymodule/actuator

从安全角度来看,我希望将执行器端点映射到/actuator。反向代理https://mydomain/api/mymodule -> http://oneofmyserver:port/mymodule上的简单配置可保护最终用户无法访问执行器。

是否可以将执行器端点映射到/actuator

3 个答案:

答案 0 :(得分:6)

从安全角度来看,可能更好的解决方案是在完全不同的端口上输出执行器。要做到这一点,只需添加这些属性:

management.port=9080

您也可以使用

更改执行器端点的上下文路径
management.context-path=/actuator

答案 1 :(得分:3)

您可以使用management.endpoints.web.base-path属性来更改管理端点的前缀。 Reference from spring-boot document

以下示例将 / actuator / health 重新映射为 / healthcheck

management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck

答案 2 :(得分:0)

如果您无法使用不同的端口并且您的环境中有 eureka,您可以使用以下内容:

  1. 配置发送到 eureka 的其他元数据。只需添加一些带有上下文路径值的参数即可。 spring docs

  2. Configure Prometheus for using Eureka。 之后,您将可以访问您的自定义元数据

  3. 最后,您可以在 relabeling step 中使用这些新参数。