Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been looking and there are a lot of people with the same problem, but there aren't a clear solution (or at least I hadn't find it).

I am using Varnish-Cache (3.0) as reverse proxy listening in port 80 for an Apache 2 webserver listening in port 88.

If I request the following URL it works fine: http://server/stuff/

But, if I request this: http://server/stuff (without the "/" at the end), the browser is redirected to the port of the backend Apache (http://server:88/stuff/).

How can I set up the behavior of Apache 2 in that situation?

Thanks in advance!

share|improve this question
up vote 2 down vote accepted

Check the UseCanonicalName directive on httpd.conf

# UseCanonicalName: Determines how Apache constructs self-referencing
# URLs and the SERVER_NAME and SERVER_PORT variables.
# When set "Off", Apache will use the Hostname and Port supplied
# by the client.  When set "On", Apache will use the value of the
# ServerName directive.
UseCanonicalName Off

You can also remove it on varnish, try this:

sub vcl_fetch { 
   if (beresp.status == 301 || beresp.status == 302) 
      set beresp.http.Location = regsub(beresp.http.Location, "^(\w+://[^/]+):\d+", "\1"); 
share|improve this answer
The Marcelo's solution worked fine, but the procedure to properly configure Apache to change that behavior would be very appreciated. I want this: $ curl -I server/stuff HTTP/1.1 200 OK Not this: curl -I server/stuff HTTP/1.1 301 Moved Permanently Thanks! (Thanks Marcelo) – a0rtega Nov 24 '11 at 19:33
I think the redirect is normal behavior, it also happens in nginx... but you may try some rewrite rule... – Marcelo Bittencourt Nov 24 '11 at 19:48
I've tested it but didn't work. This directive is disabled by default by the way, but for any reason it seems to be ignored by Apache. I suppose it's the normal behavior, and yes, it could be configured using some kind of rewrite rule. Thanks anyway, good answers! :) – a0rtega Nov 24 '11 at 19:55

Your Answer


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.