Is it possible to use HAProxy to present a different domain (or subdomain) to the client (as represented in the browser’s address bar, for example) than the one that is actually being queried on the website in the backend?
For example: suppose that I had a website at example.com, with two pages:
/page2. Could I set up a frontend in HAProxy that made it look as if example2.com was a real site, when actually it was just translating everything from example.com on a request by request basis? Thus, a request to example2.com/page1 would return the page from example.com/page1 without the end user ever knowing it?
And, if so, could this be done more delicately with subdomains? Could I ask HAProxy to convert any request made to example.com/test into test.example.com without the client ever knowing that the whole thing was virtual? So that, for example, a request to test.example.com/page3/123 took the information from example.com/test/page3/123 and re-presented it without the end-user seeing the shift?
Perhaps explaining exactly what you are trying to do might make it sound a little less malicious.
Why does this need to be on a request basis?
Ha! It’s not “malicious.” I just wondered, for example, whether HAProxy was capable of virtualizing a subdomain. Suppose that we have a site at
example.com, running in NGINX, and it has a section at
example.com/reviews/, I wondered if was possible to make it seem to the client as if that whole section is at
reviews.example.com when, within the NGINX context, it’s not “really” there.
Having played with this for a while, it seems as simple as (1) sending any requests to
reviews.example.com to a given backend, while stripping out the
/reviews part of the path, and (2) then telling the backend to (a) put that /
reviews part back in if the host is
reviews.example.com and (b) switch out the Host from
example.com when querying the backend server.
I was just thinking through to what extent HAProxy can abstract everything out.
I’m no expert, but I do believe most of what you want is possible.
Not sure you want the client to use url
reviews.example.com or that you want to embed
example.com/reviews/ on a different url. As long as you are in control of both domains it shouldnt be a problem.
This blog should put you in the right direction