How to configure Spring HATEOAS behind proxy?
Make sure your proxy is adding X-Forwarded-Host: proxy.com
header to the request that is passed to backend.com
. Then Spring Hateoas will automatically generate link hrefs with proxy.com
.
X-Forwarded-Host
can contain port.
Also see other X-Forwarded-* headers, which are supported too.
As of Spring-Boot 2.1 / Spring 5.1, Spring shifts the responsibility of handling X-Forwarded-* from Spring HATEOAS to Spring MVC.
https://jira.spring.io/browse/SPR-16668
You now require the registration of a filter bean.
Minimal implementation:
@Bean
FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter()
{
FilterRegistrationBean<ForwardedHeaderFilter> bean = new FilterRegistrationBean<>();
bean.setFilter(new ForwardedHeaderFilter());
return bean;
}