Glassfish, Apache & AJP Connector

时间:2009-7-11 14:46     作者:fshell     分类:

If we run your Glassfish application server in your local network and you want your applications to serve your internet users, we may run our Apache server in front with reverse proxy.  Apache can pass the requests to our Glassfish application server through its connector.  Glassfish supports the standard http connector and the AJP connector.  Personally, I like to to use the AJP connector because it maintains the original IP address from the client.  To use the connectors, we need to load the needed Apache modules and configure Apache and Glassfish if necessary as follow:

* HTTP connector

modules: proxy, proxy_http ProxyRequests Off <Proxy *>  Order deny,allow  Allow from all </Proxy> ProxyPass /app http://localhostname:8080/app ProxyPassReverse /app http://localhostname:8080/app

* AJP connector

modules: proxy, proxy_ajp ProxyRequests Off <Proxy *>  Order deny,allow  Allow from all </Proxy> ProxyPass /app ajp://localhostname:8009/app ProxyPassReverse /app ajp://localhostname:8009/app

If we use AJP connector, we need to copy the following jar files to the lib sub directory of our Glassfish installation directory.

* commons-logging-api.jar  * commons-modeler-2.0.jar  * tomcat-ajp.jar

For AJP to work properly for Glassfish v2, these files must come from Tomcat 5.5.23.  Files from other Tomcat versions may not work and may give
you an error: java.lang.NoSuchFieldError: USE_CUSTOM_STATUS_MSG_IN_HEADER.

To configure the Glassfish AJP connector:

From the console: $GLASSFISH_HOME/bin/asadmin create-jvm-options -Dcom.sun.enterprise.web.connector.enableJK=8009

From the console:
sudo ./asadmin create-jvm-options -Dcom.sun.enterprise.web.connector.enableJK.propertyFile = /path/glassfish/domains/domain1/config/glassfish-jk.properties  

五峰 five peaks 2010-11-30 15:52
My version of Glassfish is v2, and yours is v3.  Most likely, Glassfish v3 already includes these libraries.  If your configuration works perfectly, I think you don't need to copy these file.  Thank you for your update.
Vincent Bezzina 2010-11-07 02:50
Your instructions worked great. On a second Glassfish installation (using version 3.0.1 with JDK6) i forgot to copy across the jar files from tomcat into the glassfish lib folder. It still seems to work perfectly.

How come? Should i still copy the jar files across?