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

Solution 1:

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.

Solution 2:

I was finally able to solve this problem by changing it to the following config :

Tomcat's server.xml :

 <Connector port="8080" proxyPort="80" redirectPort="443" protocol="HTTP/1.1" compression="force" compressionMinSize="1024" 
               connectionTimeout="20000"  maxPostSize="5242880"
               URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>


 <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"  maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compr$
              compressionMinSize="1024" scheme="https" secure="true" clientAuth="false"  sslProtocol="TLS"
               keystoreFile="keystore.jks" keystorePass="PASSWORD" URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>

  <Connector port="8010" protocol="AJP/1.3" redirectPort="80" URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat">
   // Multiple webapps hosted
    </Engine>

Added this in jk.conf :

<IfModule jk_module>
        JkWorkersFile   /PATH/to/workers.properties
        JkLogFile       /var/log/apache2/mod_jk.log
        JkLogLevel      notice
        JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
        JkOptions       +ForwardURIProxy
        JkMountFile     /path/to/uriworkermap.properties
</IfModule>

workers.properties :

 worker.list = worker_app1
worker.worker_app1.type = lb
worker.worker_app1.balance_workers = app1_instance1
worker.worker_app1.sticky_session = true
worker.worker_app1.sticky_session_force = false
worker.worker_app1.method = busyness

worker.app1_instance1.type = ajp13
worker.app1_instance1.host = 127.0.0.1
worker.app1_instance1.port = 8010
worker.app1_instance1.host = localhost
worker.app1_instance1.lbfactor = 1
worker.app1_instance1.socket_timeout = 40
worker.app1_instance1.socket_keepalive = true
worker.app1_instance1.reply_timeout = 30000

uriworkermap.properties :

/|/* = worker_app1;

Added this to 000-default in sites-enabled

// This is the tomcat domain. 
<VirtualHost *:80>
ServerName www.domain_tomcat_webapp.de
ServerAlias domain_tomcat_webapp.de
ProxyRequests on
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

<Location / >
Order allow,deny
Allow from all
</Location>
</VirtualHost>

And that's it. I then started tomcat and restarted Apache web-server, it works now.