0

Ok, I'm feeling a bit stupid about this.

I'm trying to setup a simple Apache reverse proxy setup and I'm hitting a wall. I've had this setup working in the past, but now I just don't see whats going wrong. Heres the setup:

Listen 4050

ServerName lb-test
DocumentRoot /www/app

ProxyRequests Off

Header add Set-Cookie "BALANCEID=hej.%{BALANCER_WORKER_ROUTE}e; path=/;" env=BALANCER_ROUTE_CHANGED

<Proxy balancer://cluster>
    BalancerMember http://appserver1:4050 route=appserver1
    BalancerMember http://appserver2:4050 route=appserver2
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass /balancer-manager !
ProxyPass / balancer://cluster/ stickysession=BALANCEID
ProxyPassReverse / balancer://cluster/

<Location /balancer-manager>
    SetHandler balancer-manager

    Order deny,allow
    Deny from None
    Allow from all
</Location>

I can see in the log with debug turned on that requests are being routed to a balancer member, but what is also happening is that the proxy host url is also being inserted into the header.

From the lb host: curl -I localhost

HTTP/1.1 200 OK
Date: Wed, 11 Apr 2012 17:33:18 GMT
Server: thin 1.3.1 codename Triple Espresso
Content-Type: text/html; charset=utf-8
Via: 1.1 appserver2:4050
Via: 1.1 lb-test
Set-Cookie: BALANCEID=hej.appserver2; path=/;

As you can see both hosts are in the header, which is breaking the application. I would think that hitting localhost:80 would not trigger mod_proxy, right? If I hit localhost:4050, the same thing happens. Anyone know whats going on?

Thanks

cg75
  • 1
  • Can you clarify how the application is breaking due to `Via` headers? Or is it the `Host` header on the request that's causing problems? – Shane Madden Apr 11 '12 at 18:27
  • Its probably the host header. Its passing http://lb-test, appserver2:4050 through to the application. – cg75 Apr 11 '12 at 20:19
  • It should just be sending `appserver2:4050`, the multi-header format isn't allowed for `Host`. In any case, Tom's answer should be what you need. – Shane Madden Apr 11 '12 at 20:39
  • I tried that, same problem. Response headers still have: `Via 1.1 appserver2:4050, 1.1 lb-test:4050` when i hit `http://lb-test:4050/` – cg75 Apr 11 '12 at 21:00
  • Can you capture a request with `tcpdump` between the proxy and the backend server? Making guesses at the request header fields is a poor substitute for being able to actually see them. – Shane Madden Apr 11 '12 at 21:06
  • Sure. I fired up tcpdump on the proxy host and ran the client application thats configured to use it. [dumpfile](http://dl.dropbox.com/u/6783427/dump.out) – cg75 Apr 11 '12 at 21:35
  • `tcpdump` truncates packets by default, so data beyond the headers plus a little smidge of packet content isn't visible; add `-s 0` to your `tcpdump` command. – Shane Madden Apr 11 '12 at 21:39
  • New tcpdump output [newdump](http://dl.dropbox.com/u/6783427/dump.out) – cg75 Apr 11 '12 at 22:10
  • Hmm. Seems that there's a `ProxyVia On` directive in your config somewhere? It defaults to off, but it's definitely on - Apache added it in the proxy connection's request header. – Shane Madden Apr 12 '12 at 00:12
  • looks like that did the trick. thanks for taking the time to help! – cg75 Apr 12 '12 at 14:44

1 Answers1

2

you should set;

ProxyPreserveHost On

in your vhost configuration

Tom
  • 11,176
  • 5
  • 41
  • 63