0

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?

  • Please post the relevant portions of your vcl file. Also, what version of varnish? – KM. Jul 22 '13 at 19:47
6

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";
  • Had this exact problem with Varnish 3.0.5 and this answer didn't work for me unless I did set req.http.host in lower-case. Not sure if this is a bug introduced in 3.0.5 or what. – jiggy Aug 10 '15 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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