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.|
Sun GlassFish Enterprise Server 2.1 Developer's Guide - Using mod_jk has instructions for enabling the JK Connector in Glassfish.
- Follow step 3 by installing tomcat-ajp.jar, commons-logging.jar, and commons-modeler.jar in /opt/SUNWappserver/lib/
- You will also need to install log4j, or the /iwc context will not start.
- This isn't documented, so I don't know why this step is required.
- I was able to get it to work by downloading log4j from http://logging.apache.org/log4j/1.2/download.html and installing log4j-1.2.16.jar in /opt/SUNWappserver/lib/
- 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.)
- 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.
- 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.
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
This is how you can configure Apache to proxy /iwc to Glassfish
Note: ProxyPassReverse is not required.
(Experts: please advise.)
(Experts: please advise.)
- 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.
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.)