Issue with varnish passing absolute url to backend

Michael Alger varnish at mm.quex.org
Tue Feb 8 05:09:31 CET 2011


On Mon, Feb 07, 2011 at 05:22:35PM -0800, Joseph Begumisa wrote:
> 
> Just installed varnish and I have an issue with varnish sending GET
> requests to the backend server.  If I try to access
> http://test.example.com/username, varnish sends GET /username to the
> backend server running zeus web server.

This is the normal format for an HTTP request. The most basic level
looks like:

GET /username HTTP/1.0
Host: test.example.com

> The problem with this is I have a couple of rewrites on the zeus web
> server that rewrite the url http://test.example.com/username to
> http://test.example.com/profile/username.  So the GET request sent by
> varnish does not match the rewrite rule and I get back a 404 Page Not
> found error.

You will only see requests in the form of

GET http://test.example.com/username HTTP/1.0
Host: test.example.com

if the request is being made via a proxy, i.e. if the user-agent
making the request believes it is speaking to a proxy, rather than
directly to a web server.

Since Varnish is expecting to be speaking directly to an origin
server, it's not going to make proxy-style requests. Neither will
the client make proxy-style requests to Varnish, since from the
client's perspective, Varnish is the origin server.

> I can change the rewrite rule, however, is this by design or am I
> missing something in my configuration?  I'd like varnish to pass the
> GET request as the absolute url i.e http://test.example.com/username

It's definitely by design. You might be able to force Varnish to
send the absolute by doing something like:

set req.url = "http://test.example.com" req.url;

in vcl_recv, but ... I'd be hesitant to even try and see if that
approach "works".  It probably won't cause Varnish to explode, but
it's certainly an odd way of doing things.

A better solution would be to configure the web server properly.
Normally if you care about the hostname of the server, it's because
you're doing name-based virtual hosting. In this case, the web
server will receive the request, look at the Host: header that was
sent with it, and match that against a particular website. That
website can then have its own configuration, whereby it rewrites
requests of the form /username to /profile/username.

If this is purely for internal use, you might be able to work around
it by configuring Varnish as a proxy in your web browser. That still
seems like a hack though. Varnish is designed to behave like an
origin server, speaking to backends which also behave like origin
servers.




More information about the varnish-misc mailing list