Spring Boot Actuator endpoints with set server.context-path

13,909

Solution 1

Probably better solution from security perspective is to export actuator on totally different port. To do it just add such properties:

management.port=9080

You can also just change context-path of actuator endpoints by using

management.context-path=/actuator

Solution 2

You can use the management.endpoints.web.base-path property to change the prefix for your management endpoint. Reference from spring-boot document.

The following example remaps /actuator/health to /healthcheck;

management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck
Share:
13,909
Łukasz Idkowiak
Author by

Łukasz Idkowiak

Updated on June 16, 2022

Comments

  • Łukasz Idkowiak
    Łukasz Idkowiak almost 2 years

    In spring boot app I set e.g. server.context-path=/mymodule. This is convenient because I don't need to repeat over and over again /mymodule prefix in @RequestMapping. Further I want to have actuator endpoints grouped together on URLs with common prefix so I set management.context-path=/actuator. Now actuator endpoint are mapped to /mymodule/actuator.

    From security perspective I want to have actuator endpoints mapped to /actuator. Simple config on reverse proxy https://mydomain/api/mymodule -> http://oneofmyserver:port/mymodule protects that end users would not be able to access actuator.

    Is it possible to map actuator endpoints to /actuator?

    • M. Deinum
      M. Deinum over 8 years
      Instead of server.context-path set the server.servlet-path instead.
    • Łukasz Idkowiak
      Łukasz Idkowiak over 8 years
      Setting server.servlet-path causes that actuator endpoints are still mapped to /mymodule/actuator.
  • Łukasz Idkowiak
    Łukasz Idkowiak over 8 years
    Thanks, it works! I've thought earlier about this solutions, only additional port is drawback. Only problem I have is that Spring Cloud org.springframework.cloud.client.ServiceInstance do not expose management.port, so e.g. spring-boot-admin is not able to construct valid management URL to my microservice.
  • Jakub Kubrynski
    Jakub Kubrynski over 8 years
    @ŁukaszIdkowiak just submit this as issue to Spring
  • spencergibb
    spencergibb over 8 years
  • Jakub Kubrynski
    Jakub Kubrynski over 8 years
    @spencergibb Thanks :)