3

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. :-)

2
  • From your problem points seems to me you have only one IP, is this true?
    – Fredi
    Dec 3, 2015 at 13:53
  • @Fredi : Yes, one quite a good server and single IP. Dec 3, 2015 at 13:54

2 Answers 2

3
+50

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.

4
  • Thank you for the amazing answer sir, I will have to read some before proceeding..To try out first I am doing simple URL based redirection in Tomcat. I have hit a roadblock, can you kindly check : stackoverflow.com/questions/34069289/… . Dec 3, 2015 at 15:33
  • @WeareBorg done, actually the official document is way better then i can do :-)
    – Fredi
    Dec 3, 2015 at 15:59
  • I have solved the redirection problem sir, now I will get back to this. If there is any doubt, I will ask you, thanks a lot. :-) Dec 3, 2015 at 16:04
  • Hello Sir, I had partial success with this problem. I was able to run 3 webapps depending upon the URL. Now I want to run the Apache web-server and Tomcat concurrently, while still opening webapps or websites based upon URL. I have done some modifications and they are in main-post(Bottom). Can you kindly have a look. Thank you. :-) Dec 7, 2015 at 10:02
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.

4
  • 1
    Beware, first you've configured a forward proxy. Just set PorxyRequests to off, se the warning here: httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxyrequests. And another problem , you're using two different proxying modes, http with mod_proxy and ajp with mod_jk. Not sure which one is working for you, try disabling mod_jk, if that does not work means you're using ajp.
    – Fredi
    Dec 9, 2015 at 14:46
  • @Fredi : I have disabled the proxyRequests. Can you please check this question : stackoverflow.com/questions/34181013/… . Thanks a lot. :-) Dec 9, 2015 at 14:53
  • @Fredi : Were you able to check out the question sir. Thanks a lot. :-) Dec 9, 2015 at 15:12
  • I did, first you should choose which proxy module to use, if mod_proxy or mod_jk
    – Fredi
    Dec 9, 2015 at 15:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .