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

