user237865
user237865

Reputation: 1250

url redirection/mapping of the same java web application to multiple sub-domains

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

Upvotes: 2

Views: 3481

Answers (1)

JoseK
JoseK

Reputation: 31371

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

Upvotes: 3

Related Questions