2

I have a setup with a HAProxy in front of a Varnish cache who requests an Apache2 server.

The Apache is listening on an internal IP on Port 12345 and is configured with UseCanonicalPhysicalPort Off to prevent the spilling of that internal-use-only Port. I have also tested different combinations of UseCanonicalPhysicalPort and UseCanonicalName with On and Off. However, despite those canonical directives, Apache2 seems to have problems when receiving a request for a directory without a trailing slash:

UCPP: On, UCN: Not set:
Request:  https://www.example.org/test-page
Response: Redirect(301) to http://www.example.org:12345/test-page/

UCPP: On, UCN: On
Request:  https://www.example.org/test-page
Response: Redirect(301) to https://www.example.org:12345/test-page/


UCPP: Off, UCN: Off
Request:  https://www.example.org/test-page
Response: Redirect(301) without Location header

This of course won't work, as this port is only internal. The site is running a Joomla, which works fine with this setup, just those folders which would get a redirect from mod_dir don't seem to work. My Apache configuration looks like this:

<VirtualHost 192.168.150.100:12345>
    ServerName www.example.org

    UseCanonicalPhysicalPort Off
    UseCanonicalName On

    <Directory "/var/www/www.example.org">
    [...]
</VirtualHost>

Is there a way to prevent those redirects? Best would be to prevent those wrong redirects inside Apache, but I'd be open to configuration changes to Varnish or HAProxy.

Note: Please don't suggest to use port 80, as I have more than one port on Apache used by varnish(a workaround to get VHosts working better) and thus this is no option.

1 Answer 1

0

A URL for a directory without a trailing slash is not the canonical URL for this resource, this is why mod_dir redirects the user. This is a general W3C recommendation.

The redirection with your custom port is probably happening because your HAproxy or Varnish is creating a new HTTP request that is being sent to Apache. Your apache receives the very first request with the 12345 port already present. This is why the UseCanonicalName and UseCanonicalPhysicalPort seem to be ineffective.

But you can prevent apache from sending a redirect by setting the mod_dir DirectorySlash directive to Off.

If test-page is actually an existing directory on your file system, this should work fine.

You must log in to answer this question.

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