Tomcat – Hosting multiple sites on a single webapp in tomcat

apache-2.2domain-name-systemtomcat

Scenario:

I have a website – www.mydomain.com. Registered users will be given the choice of getting a permanent url to their account on mydomain.com as a subdomain like (username.mydomain.com) or they can opt to have their own domain like www.userdomain.com. So the user can access his/her account through the subdomain URL or their own hostname and the request should be forwarded to a specific url on mydomain.com.

For example: xyz.mydomain.com or www.xyz.com should give the user account from www.mydomain.com/webapp/account?id=xyz. The user should be completely unaware about where the content is coming from.

Setup:

My website is running as a webapp in tomcat 5.5.28 with apache as the web server. I am using a VPS which means I have control over all the configuration files (apache, tomcat and dns server).

Can you tell me what are the configurations needed to achieve the above scenario??

Best Answer

A "site" is a bad abstraction for thinking about webserver configuration. You webserver is dealing with 'requests'.

These requests contains 'hostname' and 'url' attributes. You can transform any request attribute with proxy and rewrite rules in apache, but you also need your application to be aware how to deal with transformed parameters.

If you fully control this application - it might be easier to check 'hostname' request header and use it as source data.

Related Topic