Spring Boot Actuator endpoints with set server.context-path
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
Łukasz Idkowiak
Updated on June 16, 2022Comments
-
Ł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 setmanagement.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 proxyhttps://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 over 8 yearsInstead of
server.context-path
set theserver.servlet-path
instead. -
Łukasz Idkowiak over 8 yearsSetting
server.servlet-path
causes that actuator endpoints are still mapped to/mymodule/actuator
.
-
-
Łukasz Idkowiak over 8 yearsThanks, 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 exposemanagement.port
, so e.g. spring-boot-admin is not able to construct valid management URL to my microservice. -
Jakub Kubrynski over 8 years@ŁukaszIdkowiak just submit this as issue to Spring
-
spencergibb over 8 yearsWe already have issues for this github.com/spring-cloud/spring-cloud-netflix/issues/425
-
Jakub Kubrynski over 8 years@spencergibb Thanks :)