Apache 2.2.x, SSL, mod_proxy and Glassfish 4.1

This entry is a small refresh about proxying with Apache, SSL, mod_proxy and Glassfish. It describes the changes that have crept in if you want to do this for Glassfish 4.1.

Requirements

Setup

If you are trying to setup the non SSL version, this is not the correct blog entry for you!

Add the following to make Apache proxy to your Glassfish application:


    ProxyPreserveHost	on
    RewriteEngine		on

    RequestHeader Set Proxy-keysize 512
    RequestHeader Set Proxy-ip %{REMOTE_ADDR}e
    RequestHeader Set Host www.mysecure.com:443

    RewriteRule ^/myapp$ /myapp/ [R,L]
    RewriteRule ^/myapp/(.*) http://localhost:8080/myapp/$1 [P,L]
        

The Host request header and the Proxy-keysize request header together make sure response.sendRedirect works properly if you proxy from a HTTPS host to a HTTP application server. The Proxy-ip header gives you access to the original IP-address of the requester.

Rewrite rule #1 takes care of the trailing slash problem; whereas rewrite rule #2 proxies your requests over to the Glassfish server running at localhost on port 8080.

Add the following attributes to your Glassfish HTTP listener, note this is a setting that has changed since Glassfish V2. Find it now under Configuration, Network Config, http-listener-x, and then select the HTTP tab, check the checkbox marked "Auth Pass Through".

Posted July 11, 2015

Up