Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
The proxy jServ, jk, jk2, warp and jk story

APACHE HTTPD TO APACHE TOMCAT CONNECTION

Ever get confused between Apache, Apache httpd and Apache Tomcat? Do you need just one of them, or both? Can they simply coexist or do you need to connect them together?

APACHE, APACHE HTTPD AND APACHE TOMCAT

The Apache Software Foundation's original 'product' was their web server; it's a fabulous piece of Open Source software and it dominates the web server world with nearly three quarters of domains hosted on it. It was originally known simply as the "Apache Web Server".

One of the tough issues with an Open Source project is managing changes that come in from a disparate range of developers and need to be rolled back into the next product release, and the Apache team had a great mechanism for this - so much so that other projects wanted to come under their wing too. And so the Apache organisation became the "Apache Software Foundation" with their mechanisms in use for both the web server product and for other bits of software too.

When Java grew and server-side Java programs were starting to be developed, the virtual machine environment and servlet specification didn't fit well with the Apache server; a purpose-designed server was needed to implement the proposed standard. And what better mechanism to use for the administration of the new project that the tried-and-tested one provided by the Apache Software Foundation?

So ... the net result is that there are TWO totally different Apache Web Servers. There's Apache httpd, which is the general purpose server that's been in use for many years but has been transformed / developed during that time to meet current needs. And there's Apache Tomcat which is the server who's main purpose is to provide Java support - that was initially in the form of Servlets, but has been extended to support JSPs (JavaServer pages) too.

DO I NEED BOTH SERVERS THEN?

Maybe. Sorry for the vague answer.

If you're running Servlets or JSPs or derivatives such as Struts of Spring then, you need Apache Tomcat or something that does the equivalent job (and Apache httpd does NOT - it would simply slow down the other functionality far too much).

Apache Tomcat CAN serve regular web content - .html documents, .jpgs, style sheets, robots.txt files and all the other things for which you need a server which, frankly, is no more than a glorified supplier of files. And Tomcat DOES also provide support for server side programming in languages like Perl or Python through the Common Gateway Interface. But this isn't really what Tomcat's intended for and it's relatively slow and clunky at the task. All right if you've a few flat pages and the occasional Perl script, but not for a busy site.

And so it's more common that not to find both Apache httpd and Apache Tomcat in use powering the same web site.

HOW ARE THE TASKS DIVIDED?

First logic might suggest that you should put all your flat content (such as HTML pages) on the faster httpd server, and your Java onto Tomcat. That would give rise to a maintenance nightmare, as your files would be grouped by type rather than by their position in your online suite of applications, with files for even a simple task spread between the servers. So there's a better solution.

Tomcat introduces the concept of a "Web Application" or a webapp. That's a bundle of all the files needed for one particular task or area of the web site. So that includes the .jsp files and servlets, the controlling file web.xml which associates a particular class with a URL, and all the internally used classes, in addition to the files that simply need to be served such as the .css .html .gif and .jpg-s.

For example, our web site at Well House Consultants comprises some 6000 different URLs. About 10% of those (but well under 10% of our traffic) relate to our library of Open Source books, which we keep in a MySQL database and access dynamically as someone searches for a book at a particular level and on a particular subject - perhaps asking only for our 'hot favourites' as a form of recommendation. This is a classic example of a web application ... in Java all the files to be served by Tomcat, including the plain form that a new arrival might be presented with.

Carrying on with the example, it's rather more arguable whether or not the help pages / FAQ for the application - flat pieces of HTML with copious images, but to server side executable content, are best served by Tomcat or httpd ... sometimes the choice is obvious but at other times it's a close call.

CAN APACHE HTTPD AND APACHE TOMCAT COEXIST

Yes, they can - but there needs to be some sort of differentiator. In other words, if I contact computer number 192.168.200.66 on port number 80 (that's the default port for a web server), I really need to have one, and only one, process there to provide me with a service. It's as if I walk up to a hotel at No. 66 on a street called 192.168.200, and knock at door number 80. I can cope if the door is answered by one person, but if no-one's there I get no service. If two people answer the door and both answer when I ask a question, their answers get mixed up and I can't handle it.

So your first step if you need both httpd and Tomcat is to install them at the same IP address but at different ports - say httpd at the (default) port 80, and Tomcat at port 8080. Any requests to port 80 are then going to be handled by httpd, and requests to 8080 by Tomcat.

Your home page is probably a fairly standard greeting to arrivals at your site, so this "httpd first" approach is a good one. The URL
 http://www.sheepbingo.co.uk
will default you to port 80, and a link within that page:
 <a href=http://www.sheepbingo.co.uk:8080/library/indesx.jsp>
would divert the user off to a webapp served by Tomcat.

This isn't a bad solution for early testing and development, but it does mean that your web site and application management team have to be very clear-minded as to what is where, and ensure that they get all the :8080 and :80s correct in the code as they link in and out of the webapp. It also doesn't look very clever to the web site user, who see himself being sent off to a different service and whether it's done using a different port number or a different IP address (also possible), he may feel the site's not really a single site. Add the that the possibility of mistakes in your support department when they're emailing a URL to a client and get the wrong server, and you'll see that a single incoming connection (IP address, Port) for both servers is desirable.

CONNECTOR PRINCIPLES

Let's carry on with our hotel analogy. I walk up to 192.168.200.66 and knock on door number 80, and I'm answered by Apache httpd. I ask him a question and he gives me an answer. Good - that's what I wanted.

Did Apache httpd know the answer himself, or did he ask someone else? In real life, we would hear him yell across the room if he had to ask and we would certainly notice if he left us standing and went across to another room - say room 8080 - to ask the occupant of that room. But, never the less, we would be happy to have asked the question at a single point of contact and got a reply even if we had to hang on for a while. This is a much more desirable state of affairs than being referred on from one person to the next ...

That's how Apache httpd and Tomcat work together. Httpd takes the "lead" role and analyses all the questions ... and passes on those that it can't directly answer to Tomcat. Tomcat's response is then passed back to the original user who, at computer speed and in computer terms, might not ever realise that httpd has referred the question on. (This business of hiding within is often referred to by the term encapsulation).

HOW IS THE CONNECTION MADE?

There are numerous ways of connection httpd and Tomcat but this has been a fast-moving field over the last couple of years and at present there are just two fully supported routes. If you see references to jk2, that was deprecated in November 2004 and if you see references to warp, that was deprecated earlier (2003?). Jserv is obsolete too - last updates are dated 2000.

Current connection routes are jk and proxy.

You may well find that some books talk about jk being replaced by jk2 and/or warp and wonder who's got it the right way round. You'll even find some references to jk being deprecated itself Jk has been around for quite a while and jk2 and warp were later introductions that to some extent were still-born - they certainly didn't take over as was predicted at one time, the time that some of those books were written. ((The Warp architecture didn't work with Windows, nor with the older Apache releases that are very common, and Jk2 was very complex to set up and really didn't take off; it eventually was deprecated when the development team melted away)).

So .. Current connection routes are jk and proxy. Dateline - late 2005. Some of the features of jk2 are being saved / rolled into jk and I do NOT foresee any major change in the short term.

PROXY CONNECTOR

The Apache httpd server (with mod_proxy enabled) simply calls up another URL internally - that other URL will be on a different port number OR on even on a different host. The results of the enquiry are passed back to the original questioner.

In other words, your user's client program (browser) calls up the httpd server. httpd then itself acts as a browser and calls up a Tomcat server.

This is simple to set up and is covered elsewhere in our training notes. Care needs to be taken within the configuration that the in-going and returned URLs are rewritten correctly. In other words - if the browser asks for "x", httpd may need to ask tomcat for "y". When tomcat replies "here is y", httpd needs to translate that back to "here is x" before it's returned to the originator.

The most common cause of problems with a proxy connection is errors in this URL rewriting; either the URLs are not rewritten at all on the return path, or they're rewritten twice. Note that this error is NOT always obvious in a first test as browsers will only use the "here is x" message they get back in a limited range of circumstances!

JK CONNECTOR

In order to provide a more flexible and efficient communication route between Apache httpd and Apache Tomcat, you may want to break away from the http protocol ((note - I say MAY - it's equally likely you don't need this flexibility and efficiency))

The jk connector uses a a protocol known as ajp rather than http.

UPDATE - DECEMBER 2005

Up to and including Apache httpd version 2.0, you had to download the jk connector as a separate operation and to ensure you had exactly the correct sub-version to work with your sub-version of httpd (not so critical on the tomcat side as it was just a protocol generator)

The new Apache httpd 2.2 includes mod_jk so this compatibility / separate download issue should be resolved.


See also jk configuration - a simple example

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

Web Application Deployment - Using Tomcat and Apache httpd Together
  [3999] Handling failures / absences of your backend server nicely - (2013-02-08)
  [3018] Tuning Apache httpd and Tomcat to work well together - (2010-10-27)
  [2482] Load balancing with sticky sessions (httpd / Tomcat) - (2009-10-29)
  [1944] Forwarding session and cookie requests from httpd to Tomcat - (2008-12-14)
  [1940] URL rewriting with front and back servers - (2008-12-14)
  [1938] Predictive Load Balancing - PHP and / or Java - (2008-12-13)
  [1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
  [1552] Extra public classes in deploying Apache httpd and Tomcat - (2008-02-24)
  [1549] http, https and ajp - comparison and choice - (2008-02-22)
  [1383] Monitoring mod_jk and how it is load balancing - (2007-10-07)
  [1376] Choosing between mod_proxy and mod_rewrite - (2007-10-02)
  [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)
  [576] Why run two different web servers - (2006-01-25)
  [436] Linking Apache httpd to Apache Tomcat - (2005-09-05)

Web Application Deployment - Further httpd Configuration
  [4307] Identifying and clearing denial of service attacks on your Apache server - (2014-09-27)
  [4001] Helping search engines with appropriate 400 error codes - (2013-02-11)
  [3955] Building up from a small PHP setup to an enterprise one - (2012-12-16)
  [3862] Forwarding a whole domain, except for a few directories - Apache http server - (2012-09-17)
  [3635] Parse error: parse error, unexpected T_STRING on brand new web site - why? - (2012-03-03)
  [3449] Apache Internal Dummy Connection - what is it and what should I do with it? - (2011-09-19)
  [3133] An image from a website that occasionally comes out as hyroglyphics - (2011-01-14)
  [2900] Redirecting a page - silent, temporary or permanent? - (2010-08-03)
  [2478] How did I do THAT? - (2009-10-26)
  [2272] Monitoring and loading tools for testing Apache Tomcat - (2009-07-07)
  [2060] Database connection Pooling, SSL, and command line deployment - httpd and Tomcat - (2009-03-01)
  [1974] Moving a directory on your web site - (2009-01-03)
  [1955] How to avoid duplicating web page maintainance - (2008-12-20)
  [1954] mod_rewrite for newcomers - (2008-12-20)
  [1939] mod_proxy_ajp and mod_proxy_balancer examples - (2008-12-13)
  [1778] Pointing all the web pages in a directory at a database - (2008-08-30)
  [1767] mod_proxy and mod_proxy_ajp - httpd - (2008-08-22)
  [1762] WEB-INF (Tomcat) and .htaccess (httpd) - (2008-08-20)
  [1707] Configuring Apache httpd - (2008-07-12)
  [1636] What to do if the Home Page is missing - (2008-05-08)
  [1619] User and Group settings for Apache httpd web server - (2008-04-22)
  [1566] Strange behaviour of web directory requests without a trailing slash - (2008-03-06)
  [1564] Default file (MiMe types) for Apache httpd and Apache Tomcat - (2008-03-04)
  [1554] Online hotel reservations - Melksham, Wiltshire (near Bath) - (2008-02-24)
  [1551] Which modules are loaded in my Apache httpd - (2008-02-23)
  [1381] Using a MySQL database to control mod_rewrite via PHP - (2007-10-06)
  [1377] Load Balancing with Apache mod_jk (httpd/Tomcat) - (2007-10-02)
  [1355] .php or .html extension? Morally Static Pages - (2007-09-17)
  [1351] Compressing web pages sent out from server. Is it worth it? - (2007-09-14)
  [1207] Simple but effective use of mod_rewrite (Apache httpd) - (2007-05-27)
  [1121] Sharing the load with Apache httpd and perhaps Tomcat - (2007-03-29)
  [1080] httpd.conf or .htaccess? - (2007-02-14)
  [1009] Passing GET parameters through Apache mod_rewrite - (2006-12-27)
  [934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
  [853] To list a directory under httpd on a web server, or not? - (2006-09-02)
  [755] Using different URLs to navigate around a single script - (2006-06-11)
  [662] An unhelpful error message from Apache httpd - (2006-03-30)
  [649] Denial of Service ''attack'' - (2006-03-17)
  [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)
  [550] 2006 - Making business a pleasure - (2006-01-01)
  [526] Apache httpd - serving web documents from different directories - (2005-12-12)
  [466] Separating 'per instance' data from binaries and web sites - (2005-10-16)
  [345] Spotting a denial of service attack - (2005-06-12)

Web Application Deployment - Using httpd to front Tomcat
  [3999] Handling failures / absences of your backend server nicely - (2013-02-08)
  [3018] Tuning Apache httpd and Tomcat to work well together - (2010-10-27)
  [2483] Clustering on Tomcat - (2009-10-30)
  [1944] Forwarding session and cookie requests from httpd to Tomcat - (2008-12-14)
  [1940] URL rewriting with front and back servers - (2008-12-14)
  [1939] mod_proxy_ajp and mod_proxy_balancer examples - (2008-12-13)
  [1566] Strange behaviour of web directory requests without a trailing slash - (2008-03-06)
  [1377] Load Balancing with Apache mod_jk (httpd/Tomcat) - (2007-10-02)
  [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)
  [576] Why run two different web servers - (2006-01-25)

Web Application Deployment - Apache httpd mod_rewrite
  [3862] Forwarding a whole domain, except for a few directories - Apache http server - (2012-09-17)
  [3753] Adding a passcode to a directory - (2012-06-05)
  [3568] Telling which ServerAlias your visitor used - useful during merging domains - (2012-01-04)
  [3339] Simplest ever proxy configuration? - (2011-06-28)
  [3197] Finding and diverting image requests from rogue domains - (2011-03-08)
  [2981] How to set up short and meaningfull alternative URLs - (2010-10-02)
  [2900] Redirecting a page - silent, temporary or permanent? - (2010-08-03)
  [2773] Dynamically watching your web site via a PHP wrapper - (2010-05-21)
  [2768] Carrying a long URL around - looking for memorable shorts - (2010-05-17)
  [2728] Redirecting a home page using mod_rewrite - (2010-04-17)
  [2555] Bookkeeping - (2009-12-29)
  [2094] If you have a spelling mistake in your URL / page name - (2009-03-21)
  [1954] mod_rewrite for newcomers - (2008-12-20)
  [1778] Pointing all the web pages in a directory at a database - (2008-08-30)
  [1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
  [1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
  [1636] What to do if the Home Page is missing - (2008-05-08)
  [1381] Using a MySQL database to control mod_rewrite via PHP - (2007-10-06)
  [1376] Choosing between mod_proxy and mod_rewrite - (2007-10-02)
  [1207] Simple but effective use of mod_rewrite (Apache httpd) - (2007-05-27)
  [1009] Passing GET parameters through Apache mod_rewrite - (2006-12-27)
  [1006] Apache httpd and Apache Tomcat together tips - (2006-12-24)
  [934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
  [755] Using different URLs to navigate around a single script - (2006-06-11)
  [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)

Web Application Deployment - Apache httpd mod_proxy
  [3892] Distributed, Balanced and Clustered Load Sharing - the difference - (2012-10-13)
  [3680] How can I run multiple web servers behind a single IP address? - (2012-04-02)
  [3339] Simplest ever proxy configuration? - (2011-06-28)
  [3293] Distributing the server load - yet ensuring that each user return to the same system (Apache httpd and Tomcat) - (2011-05-18)
  [2482] Load balancing with sticky sessions (httpd / Tomcat) - (2009-10-29)
  [2325] Apache, Tomcat, mod_proxy - (2009-08-06)
  [2273] Three recent questions on Tomcat Convertors - (2009-07-07)
  [2062] Virtual hosting and mod_proxy forwarding of different domains (httpd) - (2009-03-01)
  [1944] Forwarding session and cookie requests from httpd to Tomcat - (2008-12-14)
  [1939] mod_proxy_ajp and mod_proxy_balancer examples - (2008-12-13)
  [1767] mod_proxy and mod_proxy_ajp - httpd - (2008-08-22)
  [1566] Strange behaviour of web directory requests without a trailing slash - (2008-03-06)
  [1376] Choosing between mod_proxy and mod_rewrite - (2007-10-02)
  [1121] Sharing the load with Apache httpd and perhaps Tomcat - (2007-03-29)
  [1006] Apache httpd and Apache Tomcat together tips - (2006-12-24)
  [934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
  [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)

Web Application Deployment - Clustering and load balancing
  [4432] Java web application for teaching - now with sessions and clustering / load balancing demonstrations - (2015-02-20)
  [3892] Distributed, Balanced and Clustered Load Sharing - the difference - (2012-10-13)
  [3339] Simplest ever proxy configuration? - (2011-06-28)
  [3293] Distributing the server load - yet ensuring that each user return to the same system (Apache httpd and Tomcat) - (2011-05-18)
  [2483] Clustering on Tomcat - (2009-10-30)
  [2482] Load balancing with sticky sessions (httpd / Tomcat) - (2009-10-29)
  [2059] Sharing the load between servers - httpd and Tomcat - (2009-02-28)
  [1995] Automated server heartbeat and health check - (2009-01-16)
  [1993] Load Balancing - Hardware or Software? - (2009-01-15)
  [1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
  [1121] Sharing the load with Apache httpd and perhaps Tomcat - (2007-03-29)
  [934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)

resource index - Java
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/java-the ... story.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard