Fronting Glassfish with Apache

There are many benefits for fronting Glassfish with a web server. Not necessary Apache, could be Nginx or any other web server you seem appropriate. This article will describe how to do so for Apache.

Fronting Glassfish with Apache is also a solution to multiple SSL certificates handling, as explained here.

Among other things, fronting Glassfish with Apache will avoid exposing GF directly to the world and provide easier mechanisms for various tasks Apache is definitely less cumbersome for than GF. In short, you will get the best from both world.

For this, we will assume you have installed Glassfish V4.1.1 and Xampp 5.6.21 which itself brings Apache. However, steps will likely be similar for prior versions and for different flavors of Apache.

Basically, we will say to Apache to use mod_jk to connect to Glassfish, and to Glassfish to listen for it. We installed Xampp in the root of C: drive. Of course you will update this article code examples to your Xampp install path if different.

In Apache configuration file, which here is c:\xampp\apache\conf\httpd.conf, we set the port on which Apache is listening to 80. Find the line where it says ‘Listen xxxx’ where xxxx is a port number and replace it by ‘Listen 80”.

Next, find the bunch of lines that start with ‘LoadModule’ and at the end of it add these 4 lines:

LoadModule jk_module modules/mod_jk.so
JkWorkersFile "c:\xampp\apache\conf\workers.properties"
JkLogFile "c:\xampp\apache\logs\mod_jk.log"
JkLogLevel debug

Now, in the same folder as httpd.conf, create a new file named workers.properties with this content:

worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

Finally, open c:\xampp\apache\conf\extra\httpd-vhost.conf and add:

<VirtualHost *:80>
  JkMount /* worker1
</VirtualHost>

You are done for the HTTP Apache part, it is now ready to listen on port 80 and forward it all to port 8009 though mod_jk as soon as you restart it.

Now, log into your Glassfish admin and set network-listener-1 to listen on port 8009 instead of 80 or whatever it was. In that listener edit page there will be a setting ‘jk_listener’. Tick that box so that jk_listener is true for that network listener.

That is all. GF is now ready to listen on port 8009 for traffic sent by Apache, after you restart GF of course.

Both Apache and Glassfish are now configured to work together with Apache in front.

However, there are a few further steps to handle HTTPS, which are described here. Make sure you are doing it too if you need Apache to front both HTTP and HTTPS traffic.