1

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!

1 Answer 1

2

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"); 
   } 
} 
3
  • 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, 2011 at 19:33
  • I think the redirect is normal behavior, it also happens in nginx... but you may try some rewrite rule... Nov 24, 2011 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, 2011 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .