Search code examples
springrestspring-data-resthateoasspring-hateoas

How to configure Spring HATEOAS behind proxy?


I have Spring Data Rest with Hateoas as my backed. It is behind a proxy.

Backend url: backend.com

Proxy url: proxy.com

When I query proxy url, e.g. http://proxy.com/items/1, I get a response with href links with domain backend.com. I need the domain to be proxy.com.


Solution

  • 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.