Linux – Apache webserver & Tomcat : Runing multiple tomcat webapps and apache webserver app at same time

apache-2.2debianlinuxlinux-networkingtomcat

We have a Debian X64 server which currently has a tomcat instance where we have 3 webapps in WAR file ofcourse. Also, we have an Apache webserver, which has one CMS system running. And one final project is the Maintenance webapp, which is shown when we are working on the server and service is not available.

The problems we face are :

  1. Only one out of Tomcat or Apache web-server is actively running on Port-80 all the time.
  2. For Tomcat apps, the apps have to be accessed by their context-paths which are different.
  3. We are unable to run everything under multiple-domain names, but under single server.

What I am trying to do in long-term :

  1. Use Tomcat(preferred) or Apache web-server as a load-balancer, which will relay requests based upon domain-names. So, if someone is calling url www.xyz.com, then it should invoke the XYZ webapp which we have. Same webapp name and domain-name is purely co-incidental.
  2. Tie up the Maintenance webapp to the whole grid, which will be called when any domain is not-alive or not responding or busy.

I have created a picture(a horrible one.. 🙁 ), which explains the task a bit more illustratively.

enter image description here

As you can see now the architecture, here is/are my questions.

  1. Is this a good approach? If not, kindly tell me where and what I can do better.
  2. The task I am trying to do, what is it called? Grid-config, load-balancing?
  3. How to tie all the webapps, websites together which can be referred via different URL's, but will point to the correct webapp or website.
  4. I have a good understanding of Apache tomcat and Linux administration , not so much of Apache webserver. Can anyone help me in how to proceed with this problem, some planning and what I would require, so I can execute it.

Please note, we have domain-names registered in DNS for all the webapps and webserver based website.

I hope I have added enough information, if there is anything required, kindly let me know. Any help would be nice. Thanks a lot. 🙂

Best Answer

Considering you have only one IP and one server, i would:

Put one instance of apache Listening on port 80 with Name based virtual hosting (as you have only one IP, beware of eventual SSL problems if you plan to use HTTPS, check here: https://wiki.apache.org/httpd/NameBasedSSLVHosts)

So you'll have a virtual host for each subdomain, let's say your domain is example.com, you'll have:

www.app1.com
[...]
www.appN.com

cms.example.com
maintenance.example.com

On the virtual host that manages the app subdomains you can configure a reverse proxy, either with mod_jk, mod_proxy_ajp or mod_proxy_http, as you wish. I would choose mod_jk for tomcat.

With this, you have your 3 problems covered.

This covers your first long term plan too, for the second:

Tie up the Maintenance webapp to the whole grid, which will be called when any domain is not-alive or not responding or busy.

You can do this in various ways. For example, using an custom error page on Apache for 500 / 503 erros that redirects to your maintenace.example.com. This can be a question of it's own

As for your last questions:

1 Is this a good approach? If not, kindly tell me where and what I can do better.

I think i covered this too

2 The task I am trying to do, what is it called? Grid-config, load-balancing?

Virtual Hosting (with eventual load balancing, see later)

3 How to tie all the webapps, websites together which can be referred via different URL's, but will point to the correct webapp or website.

This is taken care for from the Apache virtual hosts and the proxy. You can even rewrite so you dont have to use the context path in the url. This can be a question of it's own too.

4 I have a good understanding of Apache tomcat and Linux administration , not so much of Apache webserver. Can anyone help me in how to proceed with this problem, some planning and what I would require, so I can execute it.

I think i covered this too.

A sidenote, i would use at least two tomcats, but better, two tomcats per app. At least two so you are covered in case tomcat dies. Two per app, so you can have your apps isolated from eachother (running in different JVM's). This is quite handy to point to a specific app in case of problems ecc.

Hope this helps.

Related Topic