Varnish sending bad “Host” header to Apache

apache-2.2varnish

I'm in the early stages of testing Varnish 3.0.4 as a new front end for a web service. I have varnish configured to listen on port 88. For its backend it's using an existing apache server running on the same host on port 80.

The trouble I'm having is that when varnish makes a request to apache, it's including ":88" in the Host http header (even though it's definitely connecting to apache on port 80.

For example:

  1. I request http://www.myservice.com:88/images/foo.gif. It makes a request to the backend.
  2. The apache backend logs the HOST header to the Apache access log – using %{Host} in the log file format
  3. The access log shows this host header as www.myservice.com:88, not www.myservice.com.

If I connect to this apache server with telnet and make identical HEAD requests but altering the value of the Host header, I see the same behavior that I witness through varnish – i.e. if I include the :88 in the host header, the request returns 404.

I've tried:

  • altering req.http.header.port and beresp.http.header.port to 80
  • altering req.http.header.host and beresp.http.header.host to www.myservice.com.

Seems like I'm missing something obvious.

How do I get varnish to send a proper Host header to apache?

Best Answer

Varnish leaves the Host header completely unmolested by default - it's sending to Apache what was sent to it. This is intended behavior - Varnish tends not to fiddle with anything unless you tell it to.

To manipulate it, put something like this in your vcl_recv, in addition to any conditional logic you need to add:

set req.http.Host = "www.myservice.com";
Related Topic