Varnish - Apache - Port 81 Trailing Slash Rewrite

Michael Alger varnish at
Thu Nov 10 14:09:20 CET 2011

On Thu, Nov 10, 2011 at 12:26:20PM +0000, Sam Davey wrote:
> I'm running varnish-2.1.5 on port 80 with an apache backend on port 81.
> I'm having a strange problem with my configuration.
> Basically I have added a new folder called 'test' in my webroot so
> I can access via  This directory only
> contains a simple html file.
> If I access the url with the trailing slash everything works fine.
> However if I access the url without the trailing slash my page hangs
> and eventually the address bar displays
> It is hanging because I don't let port 81 through my firewall.
> I do have some rewrite rules in apache but they pass through
> RewriteCond %{REQUEST_FILENAME} !-d so they should not run.
> As such I am confused.  What is causing it to try and rewrite or
> redirect to

It's standard behaviour of Apache and most web servers. The reason
is partly what you've identified -- /test and /test/ are different
URLs but end up being the same thing, so it redirects to the "one
true location" of the resource. It's also so that relative links
within that location still work. Imagine your test document embeds
an image using <img src="image.png">. If the browser thinks it's
accessing /test/ then it will fetch /test/image.png. If it thinks
it's accessing /test then it'll fetch /image.png.

> How can I configure it correctly? (BTW I am using Plesk 9.5.2 if
> that makes a difference)

Generally it's best to make your web server listen & respond to the
same host/port that clients are accessing it. So, configure it as if
Varnish wasn't there, and then slot Varnish in front of it somehow.

One way to do this is to have Apache bind to a loopback address on
port 80 (e.g., but you can use 127.anything). That way
Apache will still feel like it's living on port 80 and when it does
its stuff there's no issue.

You might be able to override Apache's notion of the port somehow;
my backends are on different servers to the proxies though so I've
never needed to deal with this.

> But that makes the content look like its coming from /test instead
> of /test/ and as such in certain circumstances I could get a
> duplicate content penalty.  Also I must be correct in thinking
> that this sort of handling should take place in the backend, not
> in varnish.

Yes, I'd definitely sort it out in the backend.

More information about the varnish-misc mailing list