mkopylec / charon-spring-boot-starter

Reverse proxy implementation in form of a Spring Boot starter.
Apache License 2.0
240 stars 54 forks source link

Ability to map by host pattern instead of just path #121

Open jwgmeligmeyling opened 3 years ago

jwgmeligmeyling commented 3 years ago

Use case: reverse proxy differently for various requested hosts.

Example syntax:

charonConfiguration()
   // ...
   .add(requestMapping().hostRegex("subdomain\..*").set(...))
   .add(requestMapping().hostRegex("subdomain2\..*").set(...))
mkopylec commented 3 years ago

Why do you need such feature?

jwgmeligmeyling commented 3 years ago

I'm using Bloomreach CMS which uses 2 different applications that need to be deployed on an application server. These applications need to be deployed under specific context paths (/site and /cms respectively). Of course no one wants to deploy their site at /site, so you need to reverse proxy this. However, Bloomreach went all their way to make it impossible to efficiently host this stuff. So after you made the site available at contoso.com/ , contoso.com/cms still won't work fully. Instead, you need to bind it under cms.contoso.com and have a reverse proxy for that as well.

Because of all the reverse proxy hell required to get Bloomreach too work (goes much beyond the standard capabilities of a load balancer like AWS EC2's one), I've decided to just deploy one extra WAR into the container with the reverse proxies for both the site and CMS. For this I need to be able to use different proxy configurations for different requested hostnames.

mkopylec commented 3 years ago

Ok. Will you manually set the Host HTTP header in HTTP client when sending request to server that uses Charon? Is it even possible?

mkopylec commented 3 years ago

To be more clear. What I see is:

Client -> Charon app (running behind some IP/domain) -> Outgoing servers (running behind some IP/domain)

Now, if you want the charon app to receive requests with Host header different than its IP/domain, you must set the header manually.

jwgmeligmeyling commented 3 years ago

The client connects through a browser, which specifies the requested host as part of the Request URL.

So both cms.contoso.com and contoso.com resolve to the proxy IP running the Charon app. Based on the requested host (set by the browser in the request URL), the proxy forwards the request to the appropiate URL.

mkopylec commented 3 years ago

Ok, I see the point now.