Apache reverse proxy: Change protocol in links and form targets from http to https

apache-2.2reverse-proxy

I have a http service running on 10.1.1.187:8080.

This is delivered as a public https service to https://public.example.com which is 10.1.1.186:443 via apache proxy magic:

<VirtualHost 10.1.1.186:443>
    ServerName public.example.com

    #Configure Reverse Proxy
    ProxyRequests Off
    ProxyPreserveHost On

    <Location />
        ProxyPass http://10.1.1.187:8080/
        ProxyPassReverse http://10.1.1.187:8080/

        Order allow,deny
        Allow from all
    </Location>

    #Define Virtual Host Specific SSL information.
    SSLEngine On
    SSLProxyEngine On
    SSLProxyProtocol all -SSLv2

    SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

</VirtualHost>

When I enter https://public.example.com in my browser and click through the certificate, I can get the first page which contains a login form:

<form action="http://public.example.com/login" method="post">
  <--  ... contains username, password fields and a send button -->
</form>

So the action target was very nice rewritten. But the http should read https. How to do that?

It would be nice if the link was changed in the form action tag, pointing to the correct https page already, rather using a second http virtual host with a rewrite condition.

Edit:

This is the additional part that solved it (I put it in the vhost but outside the Location container):

SetOutputFilter proxy-html

# On: rewrite also css and javascript - Off: only in HTML
ProxyHTMLExtended Off
# Maybe this should be switched on

ProxyHTMLURLMap http://public.example.com https://public.example.com

Best Answer

You might try http://apache.webthing.com/mod_proxy_html/. It's intended to rewrite URLs in a "proxy situation".

Related Topic