Linking Apache and Tomcat
Posted by enquirer (enquirer), 21 June 2003I have Servlets running via Tomcat (URLs on port 8080), and I'm also running Apache (standard port 80). I want to be able to access my web applications looked after by Tomcat AND all the other clever stuff such as my PHP pages all on port 80. How??
Posted by admin (Graham Ellis), 21 June 2003You'll still need to run both Apache and Tomcat ... what you do is to load a module into Apache which causes it to call up Tomcat in turn if you call up a web page that's within Tomcat's remit. As from release 4.x of Tomcat, it includes a WARP connector for the purpose - and from Tomcat 4.1 this is configured by default so there should be nothing to do there ...
What to do to Apache?
Firstly, you'll need a version of Apache that's running with dynamically loadable modules; most of them are today, but I'll add that caution just in case. Then download the connector from the jakarta.apache.org website - you're looking for the mod_webapp (a file called mod_webapp.so) which you need to move into your apache modules directory. note - you need the correct binary download for your operating system, and the apache module directory will be in different places on different OSs as well
In the Apache configuration file, add
LoadModule webapp_module modules/mod_webapp.so
after the last of the series of lines beginning LoadModule (line varies slightly on other OSs - above is Windows - on Linus last parameter is libexec.mod_wepapp.so)
After the AddModules line, add
At the end of the configuration file, add further configuration information - for example
WebAppConnection sample warp localhost:8008
WebAppDeploy firstapp sample /firstapp
Restart Apache to bring in the new configuration - in our example, the deployed web application "firstapp" that's looked after by Tomcat will now also be made available as /firstapp through Apache.
Posted by admin (Graham Ellis), 24 June 2003mod_webapp is quite a beast to configure and is very version dependent ... there's another alternative which gives you a quicker (but not so clean) linke between Apache and Tomcat - use the Rewrite engine of Apache. Again, it's a very highly configurable piece of code - but here's a quick example that takes all requests within a directory called "tomdemo" on a virtual host called sole and switches them to the server running on port 8080 on the host computer dhansak.
With Rewrite, you can even use a URL on one computer to call up a URL on a different computer!
Posted by admin (Graham Ellis), 12 July 2003I'm getting a lot of people asking about this topic. With the configuration of both Apache httpd and Tomcat, there's much associated configuration too. I'll continue to help / comment here but if anyone wants to come and study the subject, we're running a 2 day public course - see http://www.wellho.net/course/atfull.html. First course, 28th and 29th August.
Posted by admin (Graham Ellis), 11 September 2003An update ... mod_webapp has been deprecated and is no longer the top recommendation for connection Apache httpd and Tomcat.
Options available and not deprecated:
a) Simply use a different port and have your web site use the correct URL - e.g.
http://www.sheepbingo.co.uk for the httpd server
http://www.sheepbingo.co.uk:8080 for Tomcat
[edit note - your browser may highlight the above links. They're totally fictitious and don't take you anywhere ...]
b) Have Apache httpd proxy through to Tomcat, using http. Quick and easy - a few configuration lines in httpd.conf and in server.xml
c) Use a jk2 connector, which ties the two servers together more closely. The Tomcat configuration is easy (in server.xml), the httpd end requires you have a binary module for exactly the right release and operating system; either you'll need to strike lucky in finding one, or you'll end up recompiling httpd ....
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho