• Entries (RSS)
  • Comments (RSS)

Integrating GlassFish Application server with Apache web server

Posted by | Posted in GlassFish | Posted on 14-10-2008

Tagged Under : , , , ,

A typical production topology for GlassFish will be a front ending GlassFish with Apache for serving the static files. To integrate GlassFish Application Server with Apache web server follow the below steps. My Apache version was Apache/2.2.4 (Win32).

1. Download Mod JK from http://tomcat.apache.org/download-connectors.cgi. I downloaded mod_jk-1.2.26-httpd-2.2.4.so from there.

2. Rename mod_jk-1.2.26-httpd-2.2.4.so to mod_jk.so

3. Copy mod_jk.so file to modules directory of your Apache web server.

4. Create workers.properties file. I have attached my workers.properties file for reference. Most of the cases you need to change only workers.tomcat_home (Point to your GlassFish Application server installation directory) and workers.java_home (change it to your java home directory).

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
# workers.properties -
# This file provides jk derived plugins with the needed information to
# connect to the different tomcat workers.  Note that the distributed
# version of this file requires modification before it is usable by a
# plugin.
# As a general note, the characters $( and ) are used internally to define
# macros. Do not use them in your own configuration!!!
# Whenever you see a set of lines such as:
# x=value
# y=$(x)\something
# the final value for y will be value\something
# Normaly all you will need to do is un-comment and modify the first three
# properties, i.e. workers.tomcat_home, workers.java_home and ps.
# Most of the configuration is derived from these.
# When you are done updating workers.tomcat_home, workers.java_home and ps
# you should have 3 workers configured:
# - An ajp12 worker that connects to localhost:8007
# - An ajp13 worker that connects to localhost:8009
# - A jni inprocess worker.
# - A load balancer worker
# However by default the plugins will only use the ajp12 worker. To have
# the plugins use other workers you should modify the worker.list property.
# OPTIONS ( very important for jni mode ) 
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#------ ADVANCED MODE ------------------------------------------------
#------ DEFAULT worker list ------------------------------------------
# The workers that your plugins should create and work with
# Add 'inprocess' if you want JNI connector
#worker.list=ajp12, ajp13
# , inprocess
#------ DEFAULT LOAD BALANCER WORKER DEFINITION ----------------------
# The loadbalancer (type lb) workers perform wighted round-robin
# load balancing with sticky sessions.
# Note:
#  ----> If a worker dies, the load balancer will check its state
#        once in a while. Until then all work is redirected to peer
#        workers.
#worker.loadbalancer.balance_workers=ajp12, ajp13
#------ DEFAULT JNI WORKER DEFINITION---------------------------------
# Defining a worker named inprocess and of type jni
# Note that the name and the type do not have to match.
# Define 1 real worker using ajp13
# Set properties for worker1 (ajp13)

5. Edit the Apache configuration file (httpd.conf).

6. Add the following entries to your httpd.conf file.

LoadModule jk_module modules/mod_jk.so
JkWorkersFile D:/Apache22/conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T %U %q" 
# Send all jsp requests to GlassFish
JkMount /*.jsp worker1
# Send all /TestWeb/ requests to GlassFish
JkMount /TestWeb/* worker1

Change line ‘LoadModule jk_module modules/mod_jk.so ‘ to point to your mod_jk.so path. If you have copied mod_jk.so to modules directory of Apache web server you don’t need to change this line. JkWorkersFile should point to the path where you have created your workers.properties file in step 4. JkLogFile will be the log file for mod_jk. JkLogLevel set to error for production environments.

JkMount /TestWeb/* worker1, here /TestWeb/ is the GlassFish context root of your GlassFish web application.

The documentation for the above options are :-
JkWorkersFile – the name of a worker file for the Tomcat servlet containers
JkLogFile – Full path to the Tomcat module log file
JkLogLevel – The Tomcat module log level, can be debug, info, error or emerg
JkLogStampFormat – The Tomcat module log format, follow strftime syntax
JkOptions – Set one of more options to configure the mod_jk module
JkRequestLogFormat – The mod_jk module request log format string
JkMount – A mount point from a context to a Tomcat worker

7. All the configurations required at Apache web server side is over. Now you can start your Apache web server.

8. Copy tomcat-ajp.jar from Tomcat version 5.5.23 to GlassFish installation directory/ lib folder. For me all other versions gave some kind of errors and tomcat-ajp-jar from Tomcat 5.5.23 worked fine.

9. Copy commons-logging.jar, commons-modeler.jar and log4j.jar to GlassFish installation directory/lib folder. I used commons-logging.jar, commons-modeler-2.0.1.jar and log4j-1.2.7.jar.

10. Now open you domain.xml file. The domain.xml file will be inside GlassFish_HOME\domains\domain1\config folder.

11. Search for <jvm-options> in your domain.xml file and add an entry there


12. That’s it. You are done with integrating Apache web server with GlassFish Application Server. Now access your jsp page through Apache web server.



Read More

Post a Comment