Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I ran into the following problem:

tldr;

When dynamically rewriting the HTTP Host header with http-send-name-header Host haproxy seems to mess up HTTP Response headers. Doing so works fine when using nginx and proxy_set_header Host $upstream_addr;

What I need to arrive at target-machine:1234 is: Host: target-machine:1234 instead of Host: balancer:1234

Long version

We have a customer installation where only 32bit JVMs can be run, hence we are spawning n instances of the same application on n different ports:

target-machine:8766
target-machine:8767
target-machine:8768
target-machine:8769

And we do have a balancer running on a dedicated balancer machine. The clients have to be balanced based on IP (a legacy issue of the software we use).

Now we come to the ugly part: the application we intend to use, relies on the HTTP Host header field, as some operations cause it to send an internal request. In our current setup this internal request goes to the load balancer, which in turn sends it to one of the target machines, but necessarily to the target machine it originated from.

I used nginx with the Upstream Module before (but we can not anymore, as another must for this software is that HTTP Posts should not be cached by the proxy as its upload progress meter depends on this (sigh...)) and could solve this issue by adding: proxy_set_header Host $upstream_addr;, yet nginx does not support upload streaming.

I did discovered the http-send-name-header Host which probably does exactly what I need it to do (see my haproxy.cfg here) but leads to another problem that immediately disappears when I change the line to http-send-name-header $AnythingButHost

The directive adds the right server name to the header, but it seems to mess with the proxied requests as jetty closes the streams prematurely and throws org.mortbay.jetty.EofException as well as . What I need is a Host header like:

Host: target-machine:8766

instead of

Host: balancer:8181

To the browser this problem illustrates as in the following Screenshot (the size of the sent content differs from nearly complete to only a few KB).

It immediately works when I do not change the Host Header, yet it works if I change the host header to the exact same value but use nginx.

This really leaves me puzzled. If I can assist you with any more information, let me know.

share|improve this question

1 Answer 1

This is a bug in HAProxy, which was fixed in 1.4.23. See the change log and search for http-send-name-header to see the fix. I was unable to figure out the web page for the bug, but there is further discussion in a mailing list.

There is also a patch for 1.4.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.