Hi Willy,

We are migrating applications from siteA to siteB, the technology used to run 
the applications is different in these 2 sites.

All the applications in siteA share the same domain sitea.sample.com, but each 
application has its unique uri (ex:  /proxy1, /proxy2, /proxy3 ..).
We want to migrate applications in siteA to start using new technology that is 
offered in siteB, however migrated applications need to keep existing domain 
name sitea.sample.com.

siteB is managed by the different group and we have no privilege to change 
siteB's configuration.
Each application provisioned in siteB is configured to have its own vanity name 
(ex:  abc.sample.com, xyz.sample.com, ..) which is the CNAME(alias) of 
siteb.sample.com.
siteB's HAProxy uses Host header matching to route the requests to the proper 
backend application servers, for example:

acl ABC hdr_dom(host) -i abc.sample.com
use_backend SFARM-ABC if ABC

How can we configure in siteA's HAProxy to meet above requirement?  Should we 
configure HAProxy as reverse-proxy in siteA?


Thanks,
Diana


From: Willy Tarreau <[email protected]<mailto:[email protected]>>
Date: Saturday, September 6, 2014 12:48 AM
To: Microsoft Office User <[email protected]<mailto:[email protected]>>
Cc: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: Re: HAProxy equivalent to ProxyPreserveHost off

Hi Diana,

On Sat, Sep 06, 2014 at 02:37:21AM +0000, Diana Hsu (ditsai) wrote:
Hi,
Is there a HAProxy setting equivalent to apache's "ProxyPreserveHost" ?
I want to proxy the request from siteA to siteB , both sites have HAProxy 
service configured:
siteA:  sitea.sample.com
backend SFARM-PROXY1
         server PROXY1 abc.sample.com:80
backend SFARM-PROXY2
         server PROXY2 xyz.sample.com:80
         acl PROXY1 path_reg ^/proxy1$|^/proxy1/
         use_backend SFARM-PROXY1 if PROXY1
         acl PROXY2 path_reg ^/proxy2$|^/proxy2/
         use_backend SFARM-PROXY2 if PROXY2
siteB:  siteb.sample.com (it has many CNAMEs created, including abc.sample.com, 
xyz.sample.com, ?etc)
acl ABC hdr_dom(host) -i abc.sample.com
use_backend SFARM-ABC if ABC
acl XYZ hdr_dom(host) -i xyz.sample.com
         use_backend SFARM-XYZ if XYZ
acl ?...
When I access http://sitea.sample.com/proxy1 , the browser throws 502 Gateway 
Error and siteB haproxy.log shows 503 Service Not Available.
The reason is that Host header contains "sitea.sample.com" when it reaches 
siteB and there is no acl matched.
I tried using rewrite rule on Host header in siteA config:
backend SFARM-PROXY1
reqirep ^Host: Host:\ abc.sample.com
         server PROXY1 abc.sample.com:80
It didn't work because accessing http://sitea.sample.com/proxy1 returned
http://abc.sample.com/proxy1<http://sitea.sample.com/proxy1> in the browser.
We want browser to stay on sitea.sample.com and not change to abc.sample.com.

It's not clear to me, I think you're confusing two concepts :
  - request routing
  - request rewriting.

What I understand above is that you want haproxy to rewrite the Host
request header, and you forgot to rewrite the Location response header.
Please note: rewriting a Host header is a very dirty thing to do which
is always unreliable, especially when you don't know all the exact
details of the application behind the proxy. The reason is that the
server and the browser disagree on what the server name is. So if the
server emits cookies for a specific domain, it will not work fine. If
the server has hardcoded links in pages, it will not work. If the server
delivers some javascript which builds requests from hardcoded domains,
it will not work either.

In fact, I don't really understand why you want to rewrite these Host
headers instead of doing the proper thing which consists in binding the
server to the correct names. Also, by rewriting, the server loses the
information of the original host which is probably not what you want
(or what you will ultimately want).

Could you please bring in a few more explanations about what you want
to do ? Maybe there's another way to do it cleanly.

Regards,
Willy


Reply via email to