Installation Scenario - Configure Glassfish JK AJP Connector

Skip to end of metadata
Go to start of metadata

Installation Scenario - Configure Glassfish JK AJP Connector

This document explains how to enable the JK/AJP connector in Glassfish. This allows you to efficiently proxy Convergence with Apache mod_proxy_ajp, for instance.

Comms Community Contribution
This article has been received from the Comms Community. It has not yet been verified by Oracle.
This is a work in progress. Comments and patches are very welcome.

Configure Glassfish

Sun GlassFish Enterprise Server 2.1 Developer's Guide - Using mod_jk has instructions for enabling the JK Connector in Glassfish.

  1. Follow step 3 by installing tomcat-ajp.jar, commons-logging.jar, and commons-modeler.jar in /opt/SUNWappserver/lib/
  2. You will also need to install log4j, or the /iwc context will not start.
  3. Follow step 6 by adding "-Dcom.sun.enterprise.web.connector.enableJK=8009" to the jvm options.
    • Or, you can add "<jvm-options>-Dcom.sun.enterprise.web.connector.enableJK=8009</jvm-options>" directly to domain.xml. If you do this, note that the default domain.xml has two java-config sections; add it to the first section.)
  4. You will also want to follow step 7 by adding "-Dcom.sun.enterprise.web.connector.enableJK.propertyFile=/opt/SUNWappserver/config/glassfish-jk.properties" to the jvm options.
    • Or, you can add "<jvm-options>-Dcom.sun.enterprise.web.connector.enableJK.propertyFile=/opt/SUNWappserver/config/glassfish-jk.properties</jvm-options>" directly to domain.xml.
    • then install /opt/SUNWappserver/config/glassfish-jk.properties using the example config provided in the document linked above
    • note: Glassfish 2 ignores the glassfish-jk.properties file, so it is impossible to configure it to listen on a single network interface.  Glassfish 3 is claimed to have fixed this bug, but as of this writing, Glassfish 3 is not supported with Convergence.
  5. Restart Glassfish. You should see in netstat that the server is now listening on port 8009.

If Glassfish doesn't start, or it isn't listing on port 8009, or you get an error when proxying with Apache, check the server.log for errors.

Configure Apache mod_proxy_ajp

I'm using mod_proxy_ajp in this example. I don't know if it is better or worse than mod_jk. It is just what I had installed already. (Experts: please advise.)

Install mod_proxy_ajp in Apache, which you can do by specifying the "--enable-proxy-ajp" flag when you configure Apache before compiling it.

This is how you can configure Apache to proxy all requests to Glassfish

ProxyPass / ajp://<glassfish_server>:8009/

This is how you can configure Apache to proxy /iwc to Glassfish

ProxyPass /iwc/ ajp://<glassfish_server>:8009/iwc/
ProxyPass /iwc_static/ ajp://<glassfish_server>:8009/iwc_static/

Note: ProxyPassReverse is not required.

Configure Apache mod_jk (alternative to mod_proxy_ajp)

ex

 JkMount /iwc/ worker1
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.connection_pool_size=100
worker.worker1.connection_pool_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
# Glassfish server settings
address=127.0.0.1
minProcessors=20
maxProcessors=1024
maxThreads=4096
enableLookups=false
tomcatAuthentication=false

jk.conf

<IfDefine 64bit>
LoadModule jk_module libexec/64/mod_jk.so
</IfDefine>
<IfDefine !64bit>
LoadModule jk_module libexec/mod_jk.so
</IfDefine>

<IfModule mod_jk.c>
   JkWorkersFile /etc/opt/webstack/apache2/2.2//conf.d/workers.properties
   # Where to put jk shared memory
   # Update this path to match your local state directory or logs directory
   JkShmFile     /var/opt/webstack/apache2/2.2//logs/mod_jk.shm
   # Where to put jk logs
   # Update this path to match your logs directory location (put mod_jk.log next to access_log)
   JkLogFile     /var/opt/webstack/apache2/2.2//logs/mod_jk.log
   # Set the jk log level [debug/error/info]
   JkLogLevel  info
   # Select the timestamp log format
   JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
   JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories
   # JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
   JkRequestLogFormat "%w %V %T"
   JkMount /iwc/ worker1
   JkMount /iwc/svc/iwcp/change_sieveorder.iwc worker1
   JkMount /iwc/svc/iwcp/create_sieve.iwc worker1
   JkMount /iwc/svc/iwcp/delete_sievebyid.iwc worker1
   JkMount /iwc/svc/iwcp/get_allprefs.iwc worker1
   JkMount /iwc/svc/iwcp/get_sieves.iwc worker1
   JkMount /iwc/svc/iwcp/get_sievesinfo.iwc worker1
   JkMount /iwc/svc/iwcp/login.iwc worker1
   JkMount /iwc/svc/iwcp/logout.iwc worker1
   JkMount /iwc/svc/iwcp/set_senderidentity.iwc worker1
   JkMount /iwc/svc/iwcp/set_sieve.iwc worker1
   JkMount /iwc/svc/iwcp/set_userprefs.iwc worker1
   JkMount /iwc/svc/wabp/create_entry.wabp worker1
   JkMount /iwc/svc/wabp/delete_entry.wabp worker1
   JkMount /iwc/svc/wabp/get_entry.wabp worker1
   JkMount /iwc/svc/wabp/get_photo.wabp worker1
   JkMount /iwc/svc/wabp/list_books.wabp worker1
   JkMount /iwc/svc/wabp/modify_entry.wabp worker1
   JkMount /iwc/svc/wabp/remove_groupmember.wabp worker1
   JkMount /iwc/svc/wabp/search_entry.wabp worker1
   JkMount /iwc/svc/wmap/attach.msc worker1
   JkMount /iwc/svc/wmap/attach/* worker1
   JkMount /iwc/svc/wmap/cfg.mjs worker1
   JkMount /iwc/svc/wmap/cmd.mjs worker1
   JkMount /iwc/svc/wmap/listfolders.mjs worker1
   JkMount /iwc/svc/wmap/mbox.mjs worker1
   JkMount /iwc/svc/wmap/msg.mjs worker1
   JkMount /iwc/svc/wmap/spell.msc worker1
   JkMount /iwc/svc/wcap/get_freebusy.wcap worker1
</IfModule>

Glassfish AJP troubleshooting, tuning and advanced configuration

(Experts: please advise.)

mod_proxy_ajp troubleshooting, tuning and advanced configuration

(Experts: please advise.)

Other

  • You should be able to use mod_rewrite to perform configure Apache to proxy (you still need mod_proxy_ajp installed) if you need to do any url rewriting.
  • You should configure Glassfish to listen only on localhost, or a private interface, or firewall connections from only your apache server. This is important especially if you are relying on REMOTE_USER, for instance.

Why would I want to do this?

There are many reasons why you would want to do this, and it depends on your situation. Examples:

  • You depend on an Apache module
  • Load balancing and scaling
  • You are running several J2EE environments, not all Glassfish, on the same server and wish to reuse the same AJP port numbers. (My reason is I want to make the environments the same as they will be on single J2EE servers.)
Labels:
convergence convergence Delete
apache apache Delete
webmail webmail Delete
installing installing Delete
applicationserver applicationserver Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jul 25, 2012

    Consider the following suggestion under Configure Glassfish.

    There are 2 other options to add JVM options:

    1. Using the Glass Fish Web Console--- Configurations > default-config > JVM settings > JVM Options

    Click Add JVM options & enter -Dcom.sun.enterprise.web.connector.enableJK=8009, then Save.

    2. You could use the command line Go into your Glassfish installation /bin and enter theses commands :

    asadmin create-jvm-options “-Dcom.sun.enterprise.web.connector.enableJK=8009”

  2. Jul 25, 2012

    In Configure Apache mod_jk (alternative to mod_proxy_ajp)

    Instead of specifying all possible combinations for /iwc/........URI

    specify /iwc/*

    One also need to specify uri for /iwc_static/*. 2 URIs should be like:

    JkMount /iwc/* worker1
    JkMount /iwc_static/* worker1

  3. Jul 27, 2012

    For a list of mod_jk directive types one can refer:

    http://tomcat.apache.org/connectors-doc/reference/apache.html

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Oracle community and they might not be employed or in any way formally affiliated with Oracle. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Oracle nor any other party necessarily agrees with them.