Apache (http) behind load balancer (http/https) – Redirect does not preserve https

apache-2.2httpsload balancingredirect

I have two configurations – development and staging – with (supposedly) identical configurations: a set of HTTP-only Apache instances sitting behind a Citrix load balancer that allows both HTTP and HTTPS connections.

The Apache VirtualHost definitions contain the following directives:

RedirectMatch permanent /something/endpoint(.*)$ /something/otherendpoint$1
SSLProxyEngine On
ProxyPass /something/endpoint !
ProxyPass /something https://192.168.1.100:6443/something
<Location /something>
ProxyPassReverse https://192.168.1.100:6443/something
</Location>

So, I want to proxy any requests for /something to a different backend HTTPS server, except for /something/endpoint, which I need to redirect.

Now, everything is working fine in my development environment. I can access http://hostname/something/endpoint and it will redirect me to http://hostname/something/otherendpoint. Likewise, I can access https://hostname/something/endpoint and it will redirect me to https://hostname/something/otherendpoint.

But in the staging environment, both http://hostname/something/endpoint and https://hostname/something/endpoint redirect to http://hostname/something/otherendpoint – it does not preserve HTTPS.

I have been pulling my hair out trying to figure out what the difference is between the two configurations. There must be something causing Apache to not respect the access protocol, but I'm not able to isolate it. The HTTP response headers look the same in both environments, except for the redirect Location header that specifies http instead of https.

Any ideas about what configuration difference could be causing this?

Best Answer

Please remember that permanent redirects get cached by your webbrowser, you will need to either manually clear the browser cache after each test/modification in your configuration or test in "incognito"/"anonymous" browser windows.

How apache httpd merges configuration directives can be a bit tricky. The syntax you're using seems a bit inconsistent and might be the cause of your issues:

ProxyPass /something https://192.168.1.100:6443/something
<Location /something>
ProxyPassReverse https://192.168.1.100:6443/something
</Location> 

For clarity please use either:

ProxyPass /something/endpoint !
ProxyPass /something https://192.168.1.100:6443/something
ProxyPassReverse /something https://192.168.1.100:6443/something

or enclose everything in Location directives:

<Location /something>
  ProxyPass  https://192.168.1.100:6443/something
  ProxyPassReverse https://192.168.1.100:6443/something
</Location>
<Location /something/endpoint>
  ProxyPass  "!"
  Redirect permanent /something/otherendpoint
</Location>