Setting Apache server to access Glassfish

There so many cases why somebody might want to set Glassfish server behind Apache, that I won’t list them all.
I think that emotional aspect is the most important here – people feel uncomfortable with ports other, than traditional 80 and 443.

So, I decided, that it would be much better if our server will be not on port 8080, but in root of usual domain.

I started from a wonderful article Setting up Glassfish behind Apache
I followed the steps, listed in the article, but met some issues with setting up mod_jk modile.

Configure Glassfish

Create the listener:

$GLASSFISH_HOME/glassfish/bin/asadmin --user admin --host localhost --port 4848 create-http-listener --listeneraddress --listenerport 8009 --defaultvs server jk-connector-8009

Activate the listener:

$GLASSFISH_HOME/glassfish/bin/asadmin --user admin --host localhost --port 4848 set

Finally, restart the Glassfish Server:

$GLASSFISH_HOME/glassfish/bin/asadmin stop-domain
$GLASSFISH_HOME/glassfish/bin/asadmin start-domain

Compile mod_jk

1. download sources from The Apache Tomcat Connector
2. uncompress
3. install http-devel package
4. Configure for build

$ ./configure --with-apxs=/usr/sbin/apxs

5. Make binaries

$ make

6. Copy library to modules

$ sudo cp ./apache-2.0/ /usr/lib64/httpd/modules/

7. Add to the list of modules in your Apache config

LoadModule jk_module modules/

Configuring Apache

Create a file called and place it in a safe place (e.g. /etc/httpd/conf.d). Put the following contents in this file:


Then, open your httpd.conf file and put the following contents in it (outside a VirtualHost section). Check the path of your file

JkWorkersFile /path/to/
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"

Also, you need to add a VirtualHost section in your page, in order to map the specific domain/subdomain with the path in Glassfish you want to make visible through Apache:

  ... other stuff
  JkMount /myapp/* worker1
  ... other stuff

Set your web module in root of glassfish server

just deploy your war with the following parameter:

$GLASSFISH_HOME/bin/asadmin deploy --contextroot "/" module.war

If you want to see this configuration in action, open our “Is it kosher? search” web app.

Leave a Reply

%d bloggers like this: