Wednesday, April 04, 2007

Setting Up Apache Forwarding to Glassfish

Okay, so I've been messing around with a GoDaddy dedicated server and I must say I'm very impressed with how the box is set up and is running. Just the other day I set up the preinstalled Apache server to forward jsp requests to my GlassFish install on that box. I found it to be a little confusing at first, so I wrote down the steps I took to get everything working - here they are:

Apache can forward requests to Glassfish by using a mod called mod_jk. This mod is installed on the Fedora Core 4 so we don't need to install it ourselves. There are two parts to setting this functionality up: Configuring Glassfish and Configuring Apache config files.

Configuring Glassfish
There are two steps to configuring Glassfish to accept forwarding from Apache:
Add the following line to the Glassfish JVM options:
  • -Dcom.sun.enterprise.web.connector.enableJK=8009


Make sure the following files are in the Glassfish Server's classpath:

  • tomcat-ajp.jar - Tomcat 5.5.16 version
  • commons-logging.jar - version 1.0.4
  • commons-modeler.jar - version 1.1

Do the above steps, bounce Glassfish, and then you should be listening on port 8009. You can verify this by running, 'netstat -a grep 8009'. If there is something listening on that port, you should be good to go.

Configuring Apache
GoDaddy's Fedora Core 4 Apache install is almost set up for what we want to do. The apache install/config files are located in /etc/httpd. Go to this directory and modify the following files:

conf/worker.properties - The config file is already set up with a worker named ajp13w, however it is not added to the worker.list. Assuming that the ajp13w is not used by anything (ie tomcat) you should be able to add your worker to the list with no problem.

conf.d/jk.conf- I added the following lines to the end of the file:

  • JkLogFile /var/log/httpd/mod_jk.log
  • JkMount /*.jsp ajp13w

After this has been done, bounce the httpd service (as root run 'service httpd restart').

Finished

Now that all this is done, your Apache server should forward all requests ending in .jsp to Glassfish.

I used the following Blogs to figure out all this stuff:

http://blogs.sun.com/dadelhardt/entry/loadbalancing_with_mod_jk_and_glassfish
http://weblogs.java.net/blog/jfarcand/archive/2006/03/running_glassfi_1.html

0 Comments:

Post a Comment

<< Home