Apache 2.4.x, SSL, mod_proxy and Glassfish 4.1

To proxy Apache 2.4.x successfully a slight adjustment was needed, but to be complete I have included all the instructions



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 Setifempty Proxy-ip %{REMOTE_ADDR}s
    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 12, 2015