2

I've a domain, say www.domain.com. And I've developed a java web application, say jwa. Now I want to install the same app for different clients using subdomains, what is the best solution possible?

something like "client1.domain.com" points to "client1" (renamed jwa)

I know we can get client1.domain.com/client1/ but client1 twice isn't good. or at least Can we get client1.domain.com/jwa/, without have multiple tomcat instances? btw, I'm running apache http server on the same server and using "proxy_module" for java/tomcat apps

Regards

user237865
  • 1,250
  • 4
  • 19
  • 41

1 Answers1

3

You dont need multiple Tomcat instances - you can point multiple clients across multiple subdomains to use the same web app

BUT be sure that this fits with your business use case - i.e. do you actually want multiple instances of the webapp running, or a can single instance serve all your clients.

I'm referring to the branding/logo/shared data/look-and-feel etc - is that common across all clients?

Lets assume it is.

With an Apache configured, the right way is to use VirtualHost directives along with mod_proxy.

A configuration like this on the Apache side should work - create one per subdomain, and point the ProxyPass and ProxyPassReverse to the Tomcat web app

<VirtualHost *:80>
  ServerName client1.domain.com

  ProxyRequests Off
  ProxyPreserveHost On

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyPass /jwa http://client1.domain.com:8080/jwa
  ProxyPassReverse /jwa http://client1.domain.com:8080/jwa
</VirtualHost>

Related Reading

Apache docs have lots of examples of VirtualHost configuration

There is also a solution without Apache httpd, you can configure Host entires within Tomcat server.xml but Apache is a better place to manage your domain URLs

JoseK
  • 31,141
  • 14
  • 104
  • 131
  • Thanks for the response, but different clients have different look-and-feel. Also, I do not want to show them /jwa in the url, but instead I would say client1.domain.com and it should point to client1.domain.com/jwa internally. (because domain itself is the web app name) – user237865 Oct 19 '10 at 20:17
  • @user237865: Yes, that can be done. You have to set /jwa as the default web app for each domain within Tomcat, then it will not be shown in the URL. See my earlier answer on how to achieve that.http://stackoverflow.com/questions/3708077/how-do-you-map-a-sub-domain-to-a-webapp-on-tomcat-6-including-the-root-webapp/3708876#3708876. In your case you will need a different copy of /jwa webapp for each client, something like jwaclient1, jwaclient2 etc since you need differnt functionality as you said. – JoseK Oct 20 '10 at 05:17
  • Jose, I tried what you said: In apache http.conf >> ServerName client1.domain.com ProxyRequests Off ProxyPreserveHost On Order deny,allow Allow from all ProxyPass / http://client1.domain.com:8080/ ProxyPassReverse / http://client1.domain.com:8080/ In tomcat server.xml ...... but still when I try client1.domain.com it is giving 404 error, any suggestions. – user237865 Oct 26 '10 at 07:03
  • Does client1.domain.com:8080 directly hit to Tomcat serve your /jwa app? First try to resolve that, then you should check from Apache – JoseK Oct 26 '10 at 07:49
  • Jose: I've tried this , I'm able to see the index.jsp in the webcontent so client1.domain.com is recognising. But I've a folder admin (admin module) inside that I'm using few files from root as /common/includes/header.jsp It says "File "/common/includes/meta.jsp" not found" - Jasper Exception. Any suggestions why the error and how to fix it, Thanks. – user237865 Oct 26 '10 at 09:54
  • Thats a completely different problem, so ask a new question. – JoseK Oct 26 '10 at 10:04