Integrating Apache with Tomcat Weblogic and Websphere Application Server

Friday, July 4, 2008

Integrating Apache with Application Servers

S.Prasanna,
sprasanna199@gmail.com

This article discusses the procedure for Integrating Apache (2 and above) with three Application servers,namely Apache Tomcat (Tomcat 5.x), BEA Weblogic server (8.1) and IBM Websphere Application server 5.x.

1. Web Servers and Application Servers

Before proceeding, one needs to understand the definition and the difference between a Web Server and an Application Server and why they are integrated.

A Web Server is a HTTP server program, which accepts browser requests from the client and sends the response back to the client. In a three-tier architecture, the Web server receives the HTTP requests and passes it to the application server program,which services the request. A Web server understands only the HTTP protocol.Examples of commonly used Web servers include Apache, Zeus, IIS, Sun ONE, etc.

Figure 1: Three tier architecture

The application server is the one, which services the client requests. Typically the Application server provides a platform for deploying business applications across the web. The application server contains the code that implements the functionality of the application (Business logic). Most of the application servers are Java based, example Tomcat, Bea Web logic, IBM Websphere, etc. The application server serves dynamic contents like servlets, JSPs, etc. In short, the application server provides access to business logic for the client.

Advantages of Web Server Application Server Integration:

Improved Performance:

Since the Web server and the application server are logically separated (sometimes they will be in a different box too), the Web Server can serve all static pages (HTML, etc) while delegating the application server to handle other dynamic content which improves performance.

Load Balancing:

It is possible for a Web server to load balance requests to one or more application servers.

Security:

Since the Web server is the one, which is exposed to the real world, and since its service levels are less compared to an application server, the web server can be hardened to prevent attacks. The Web server can also act as a reverse proxy in some cases. A reverse proxy is one, which stands between an application server and many clients. A Web server in this way can act as an application level gateway, monitoring all traffic from the clients, thus preventing HTTP level attacks.(See www.modsecurity.org for details).


2. Procedure for Integrating Apache with Application servers

Note:

From here, APACHE_HOME will be used as a reference for the root directory of Apache HTTP server installation.

This section discusses integrating apache with three Application servers namely Tomcat, BEA Weblogic and IBM Web sphere Application server.

2.1 Integrating Apache 2.x with Tomcat 5.x

Steps for integrating Apache with Tomcat using mod_jk2:

1.Download the mod_jk2 module from http://jakarta.apache.org

From Apache side:

1. Copy the module file mod_jk2.so file in the APACHE_HOME/modules directory

2. Add these two lines in the httpd.conf file in the APACHE_HOME/conf directory

LoadModule jk2_module modules/mod_jk2.so
JkSet config.file conf/workers2.properties

3. Create a file workers2.properties in the APACHE_HOME/conf directory and add these lines.

# Example socket channel, override port and host.

[channel.socket:localhost:8009]
port=8009
host=127.0.0.1

# define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009

# Map the default Tomcat directory to the Web server uri space
[uri:/*]
group=ajp13:localhost:8009

From Tomcat side:

1. Goto TOMCAT_HOME/conf directory and add these lines in the jk2.properties file

handler.list=apr,request,channelJni
channelSocket.port=8009

channelJni.disabled = 0
apr.jniModeSo=inprocess

(Just Uncomment these lines in the jk2.properties file,make sure that port number is 8009)

Now if you type

http://127.0.0.1/, you will get the default Tomcat Homepage (http://127.0.0.1:8080).

Steps for Apache with Tomcat using mod_proxy:

From Apache side:

Edit the httpd.conf file in the <APACHE_HOME>/conf directory

Add the following lines:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so

#Here Apache and Tomcat are running in the same machine.
#Change the IP address to x.y.com if Tomcat is running in a
#different box

NameVirtualHost 127.0.0.1:80

#Here Apache is configured as a proxy server

<VirtualHost 127.0.0.1:80>
ProxyPass / http://127.0.0.1:8082/
ProxyPassReverse / http://127.0.0.1:8082/
</VirtualHost>

#Note: Port 8082 in Tomcat 5 recieves the proxied requests from Apache

From Tomcat side:

Uncomment these lines in the <TOMCAT_HOME>/conf/server.xml if commented (where TOMCAT_HOME is the TOMCAT installation directory.)

<!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
<!-- See proxy documentation for more information about using this. -->

<Connector port="8082"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false"
acceptCount="100" debug="0" connectionTimeout="20000"
proxyPort="80" disableUploadTimeout="true" />


2.2 Integrating Apache 2.x with BEA Weblogic 8.1

1. Goto WL_HOME\Server\bin and locate the file (where WL_HOME is the Weblogic installation directory)

mod_wl_20.so (Regular Strength encryption)
mod_wl28_20.so (128 bit encryption)

2. Goto APACHE_HOME\modules directory and copy the above file(s)

3. The Apache HTTP Server Plug-In will be installed in your Apache HTTP Server Installation as an Apache Dynamic Shared Object (DSO) which is based on mod_so.c. Make sure it is enabled (By default it should be enabled) by executing the command below.

APACHE_HOME\bin\apache -l (You should see mod_so.c in the output).

4.Edit the Apache httpd.conf file in APACHE_HOME/conf directory and add these lines

#Weblogic configuration details

LoadModule weblogic_module modules\mod_wl_20.so

#Location tag is added only for proxy support by path
#It will take precedence when proxying by MIME type
#is also enabled

<Location /weblogic>
SetHandler weblogic-handler
PathTrim /weblogic
#ErrorPage http://myerrorpage.mydomain.com
</Location>

#Proxying requests by MIME type

<IfModule mod_weblogic.c>
WebLogicHost 127.0.0.1
WebLogicPort 7001
MatchExpression *
</IfModule>

5. Test the syntax of the httpd.conf file using the command

APACHE_HOME\bin\apache -t (You should see SYNTAX OK as output).

6. Restart Weblogic and Apache.

Now if you type

http://127.0.0.1, it should lead to the Weblogic home page (provided the <Location> definition was not there, else it will take precedence and instead of http://127.0.0.1 you have to type http://127.0.0.1/weblogic/ to see the Weblogic Home Page).

Steps for Apache with Web logic using mod_proxy:

From Apache side:

Edit the httpd.conf file in the <APACHE_HOME>/conf directory

Add the following lines:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so

#Here Apache and Web logic are running in the same machine.
#Change the IP address to x.y.com if Weblogic is running in a
#different box

NameVirtualHost 127.0.0.1:80

#Here Apache is configured as a proxy server

<VirtualHost 127.0.0.1:80>
ProxyPass / http://127.0.0.1:7001/
ProxyPassReverse / http://127.0.0.1:7001/
</VirtualHost>

#The default listening port for BEA Web logic application server is 7001

Now if you type

http://127.0.0.1 it should lead to the Weblogic home page.


2.3 Integrating Apache 2.x with IBM Web sphere 5.1 x and above

1. Download the Web server plugins for Websphere 5.x from

http://www-1.ibm.com/support/docview.wss?uid=swg24007227 for (5.1x)

http://www-1.ibm.com/support/docview.wss?uid=swg24007265 for (5.0x)

2. Get the file mod_was_ap20_http.dll from the plugin and copy it in

Apache modules directory i.e <APACHE_HOME>/modules directory.

3. Get the plugin-cfg.xml (from Websphere) file

This can be got by

1. Running the command GenPluginCfg in the

<WAS_ROOT>\bin directory (GenPluginCfg.bat)
(where WAS_ROOT is the Websphere Application Server installation directory)

The Plugin-cfg.xml file will be created in the location

<WAS_ROOT>\config\cells\plugin-cfg.xml

2. Running Websphere admin console and exporting the plugin.

Login to the admin console (at port 9090 i.e 127.0.0.1:9090) (This doesn’t require a user ID or a password)

Goto Environment -> Update Web Server Plugin

Click OK to update the plugin configuration file.

The Plugin-cfg.xml file will be created in the location below

<WAS_ROOT>\config\cells\plugin-cfg.xml

4. Copy the plugin-cfg.xml file in Apache modules directory
i.e <APACHE_HOME>/modules directory.

5. Add these lines in the httpd.conf file in the <APACHE_HOME>/conf directory.

LoadModule was_ap20_module modules/mod_was_ap20_http.dll
WebSpherePluginConfig modules/plugin-cfg.xml

6. You can change the location of the log file generated by the plugin by editing the plugin-cfg.xml file. For example, if the Plugin
error log is to be generated in the apache logs directory, the plugin-cfg.xml file can be edited as follows.

<Log LogLevel="Error" Name= "<APACHE_HOME>\logs\http_plugin.log"/>

A simplified form of the plugin-cfg.xml file is shown below.

<Config>
<Log LogLevel="Error" Name="<APACHE_HOME>\logs\http_plugin.log"/>

<VirtualHostGroup Name="default_host">
<VirtualHost Name="*:80"/>
</VirtualHostGroup>

<ServerCluster Name="MyCluster">
<Server Name="server1">
<Transport Hostname="Server-host" Port="9080" Protocol="http"/>
</Server>
</ServerCluster>

<UriGroup Name="MyURIs">
<Uri Name="/snoop/*"/>
<Uri Name="/*"/>
</UriGroup>

<Route ServerCluster="MyCluster" UriGroup="MyURIs" VirtualHostGroup="default_host"/>
</Config>

7.Now restart Websphere and Apache server and type

http://127.0.0.1/snoop and you can see the Websphere's snoop servlet in the browser.

Steps for Apache with IBM Web sphere using mod_proxy:

From Apache side:

Edit the httpd.conf file in the <APACHE_HOME>/conf directory

Add the following lines:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so

#Here Apache and Web logic are running in the same machine.
#Change the IP address to x.y.com if Websphere is running in a
#different box

NameVirtualHost 127.0.0.1:80

#Here Apache is configured as a proxy server

<VirtualHost 127.0.0.1:80>
ProxyPass / http://127.0.0.1:9080/
ProxyPassReverse / http://127.0.0.1:9080/
</VirtualHost>

#The default listening port for IBM Websphere application server is 9080
#If you want to proxy requests for admin console, use 9090 instead.

Now restart the Apache server and type

http://127.0.0.1/snoop

and you can see the Websphere's snoop servlet in the browser.

24 comments:

Anonymous said...

Hi Prasanna,
I am trying to integrate Websphere application server 6.0 with Apache HTTP server 2.2.10.
I followed your document, posted at http://www.prasannatech.net/2008/07/integrating-apache-tomcat-weblogic.html.
I couldn't find the plugin for Websphere 6.0, so I just followed steps under 'Steps for Apache with IBM Web sphere using mod_proxy'.
But I couldn't integrate both servers properly.
I got following trace in the logs -
[Wed Nov 05 11:19:36 2008] [notice] Child 5988: Starting thread to listen on port 9081.
[Wed Nov 05 11:19:36 2008] [notice] Child 5988: Starting thread to listen on port 80.
[Wed Nov 05 11:20:03 2008] [debug] mod_proxy_http.c(56): proxy: HTTP: canonicalising URL //127.0.0.1:9061/ibm/conole
[Wed Nov 05 11:20:03 2008] [debug] proxy_util.c(1489): [client 127.0.0.1] proxy: http: found worker http://127.0.0.1:9061/ for http://127.0.0.1:9061/ibm/conole
[Wed Nov 05 11:20:03 2008] [debug] mod_proxy.c(988): Running scheme http handler (attempt 0)
[Wed Nov 05 11:20:03 2008] [debug] mod_proxy_http.c(1924): proxy: HTTP: serving URL http://127.0.0.1:9061/ibm/conole
[Wed Nov 05 11:20:03 2008] [debug] proxy_util.c(2045): proxy: HTTP: has acquired connection for (127.0.0.1)
[Wed Nov 05 11:20:03 2008] [debug] proxy_util.c(2103): proxy: connecting http://127.0.0.1:9061/ibm/conole to 127.0.0.1:9061
[Wed Nov 05 11:20:03 2008] [debug] proxy_util.c(2201): proxy: connected /ibm/conole to 127.0.0.1:9061
[Wed Nov 05 11:20:03 2008] [debug] proxy_util.c(2356): proxy: HTTP: fam 2 socket created to connect to 127.0.0.1
[Wed Nov 05 11:20:03 2008] [debug] proxy_util.c(2468): proxy: HTTP: connection complete to 127.0.0.1:9061 (127.0.0.1)
[Wed Nov 05 11:20:03 2008] [debug] mod_proxy_http.c(1701): proxy: start body send
[Wed Nov 05 11:20:03 2008] [debug] mod_proxy_http.c(1790): proxy: end body send
[Wed Nov 05 11:20:03 2008] [debug] proxy_util.c(2063): proxy: HTTP: has released connection for (127.0.0.1)
and my browser throws this error -
SRVE0017W: A WebGroup/Virtual Host to handle /ibm/conole has not been defined
Any help/guidance is appreciated.
Regards,
Ajay

Prasanna Seshadri said...

Hi Ajay,

Its very important that you use the right plugins from the IIS side to get the integration correct.

In the past I have seen people getting it right with the mod_proxy solution, so try to get the right plugin for IBM Websphere 6.0.

These days I rarely work in Windows so I don't have the setup with me but in general I am sure that if you use the right plugins integrating using mod_proxy should be straightforward.

Anonymous said...

Hi Prassanna,

I tried to follow your first method for integrating apache2.2 wih websphere 6.1.I found the right Dll for my websphere version 6.1.but the apache is not throwing error on trying to restart the apache saying "cannot load the specified dll module".

Also please mention the prerequisites for making the entire thing to happen,like should plugin should already be installed in websphere or just placing the dll file should be sufficient as the trial version of websphere doesnt actually come with plugin.
Please the make the document complete in itself.

Thank you in advance.

Prasanna Seshadri said...

Hi,

Thanks for your comments, I wrote that document some time back and the procedure applies only to that particular version of app server/apache combination, also I don't have such a configuration these days, therefore not sure what may have changed.

One thing I always recommended for everyone is to use apache mod_proxy method if the regular procedure doesn't work as I saw many persons able to connect using mod_proxy easily, do let me know if that works for you.

rini said...

Hi,
I am trying to integrate Websphere application server 6.1 with Apache HTTP server 2.0. I have a trial version of WAS6.1 . I couldn't find the right plugins for websphere6.1 so I manually generated the plugin-cfg.xml. Now I dont know how to get the appropriate dll or *.so.

Puneet said...

That's wonder man. Very well explained. Keep it up !!

Prasanna Seshadri said...

Thanks Puneet.

Prasanna Seshadri said...

Hi rini,

I did this writeup some years before and I no longer work in Windows these days, therefore it may work only in those versions of Apache or WAS or Weblogic described in the article, although with minor tweaks it will work on latest versions.

For more information, you may look into the respective sites or use a module like Apache mod_proxy which will make your work simple.

Hari said...

Nice post dude

Prasanna Seshadri said...

Thanks Hari.

shahid said...

Hi Prasanna

Thank for the Post.
I helped me in tweaking "Apache plug-in for weblogic"

This help prompts me to start blogging on technology issues which got resolved and their workaround

Cheers
shahid

Anonymous said...

Hi Prasanna,

I was following your steps for "2.2 Integrating Apache 2.x with BEA Weblogic 8.1".

1. So I copied "mod_wl_22.so" from the C:\bea\weblogic92\server\plugin\win\32 folder (my WL_HOME is c:\bea\weblogic92) into the C:\Program Files\Apache Software Foundation\Apache2.2\modules folder. I didn't find it in the 'WL_HOME\server\bin' folder like you mentioned in your blog and I'm assuming this is because BEA has subsequently changed the location of these files. BTW, I was using Apache 2.22 with WL 9.2.

2. I also made sure mod_so.c is enabled by executing httpd -l

3. I copied the following into the httpd.conf file:

LoadModule weblogic_module modules\mod_wl_20.so

?IfModule mod_weblogic.c?
WebLogicHost MD1AS297
WebLogicPort 7001
MatchExpression *.do
MatchExpression *.gif
MatchExpression *.jsp
MatchExpression *.js
MatchExpression *.css
MatchExpression *.png
MatchExpression *.jpg
MatchExpression *.class
MatchExpression *.java
MatchExpression *.xml
?/IfModule?

BTW, I'm using "?" above to substitute "<" or ">" since blogger wouldn't let me use them.

4. I tested the syntax for httpd.conf using httpd -t

5. Restarted Apache and WL

6. However, when I type http://localhost, I dont get the WL homepage.

Would you know what I'm doing wrong? Otherwise I must say your steps are very precise and simple to follow unlike what they have on the oracle.com site.

Thanks much,
Alex

Madhu said...

Hi Prasanna,
I'm trying to configure reverseproxy (SSL) on apache 2.2.3, and I have installed SOA components on Weblogic 9.2 MP3. From the proxy server I'm able to access all the SOA components successfully. Only when I access the weblogic console, I will have problem.
After logging into the Weblogic console, I'm not able to see the icons and there if I click on the Lock & Edit button it shows page not found error.
I have followed your steps for configuring the weblogic with Apache.
Please advice am I missing anything.

Regards,
Madhu

Gopi said...

Hi Prasanna,
Really nice post. keep it up.

Anonymous said...

Hi,

Thanks for this nice post.

I want to do a SSO configuration with a reverse proxy.

I've a configuration with an Apache 2.2 as Reverse proxy on an domain like appli1.domain.com, configure in a virtualhost like your post , that works
But the REN server is configure with my local authentication domain like *.myprivatedomain.com.
THEN i ve an error "your URL must contain domain *.myprivatedomaine.com when the user try to connect to appli1.domain.com.

if you have an idea ?

vivek said...

"problem with websphere"
Hi S.Prasanna,
is there any way to configure url in httpd.conf of ibm http webserver like in weblogic "MatchExpression *.java"
same way for Url mapping for websphere

virendra said...

Hi Prasanna,
I am trying to integrate Websphere application server 7.5 with IBM Apache HTTP server 7.
I followed Steps for Apache with IBM Web sphere using mod_proxy. and this works fine for me I am able to redirect URLfrom Apache to Websphere.
NO w my problem is need to separate the URL for static content and dynamic content.
Like request for css,js,image files should be served by apache and other will be served by Websphere.
I am new to this thing can you suggest me how i can achieve that.
Where i have to define mapping for these urls.
I have a folder in my apache directory named static which has all the static files. I want to redirect all the urls for static content to this folder .
Please help me
Regards

Anonymous said...

how to configure the static html,js,css and dynamic jsp,servlets in Apache using Weblogic server

Pratap said...

Can the web server and app server be in different domains. I have problem reading cookies set by the web server in our servlets.

Anonymous said...

To Virendra's request for help serving up content outside of the plugin:

http://publib.boulder.ibm.com/httpserv/ihsdiag/plugin_alter_uri.html#PROXY

Anonymous said...

Hi Prasanna,

I read integrating Web server with App server. It was nice.


Thanks for your explanation.

Suggesstion: expection some more explanation.

By,
Rajalingam

Malini said...

I just read..this is really nice..

NIKHIL said...

Nicely written

Search Engine Optimization SEO said...

Best & Top Web Design, website design, software companies, Website Development Company in Bangalore, India
Embassy IT solution is the best web design company in Bangalore India, Web are providing services for Web design, Website designing, Web development, Web portals, Application Software development, Visitor management Software, Invoice billing software, Sales invoice software, Web hosting & Domain booking -Search Engine Optimization.


Copyright © 2016 Prasanna Seshadri, www.prasannatech.net, All Rights Reserved.
No part of the content or this site may be reproduced without prior written permission of the author.