Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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??

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

Not enough info. Depends on what your app does and it's architecure.

One suggestion

Can you use an apache front end with proxy passing or ajp?

Create a virtual host for each domain, different DocumentRoot for each, so stuff like images and skins can be kept separate per domain, different log if you want etc.

I think the configs would be something like this, however I am doing this from memory and don't currently have the facilities to test so use the config suggestion below as a rough idea - it's not a working implementation.

You can replace the proxy passing with proxy_ajp if you have that set up- actually I think proxy_ajp would be a better solution but my memory doesn;t stretch that far.

<VirtualHost *:443>
  ServerName www.userdoman.com
  ServerAlias userdomain.com
  DocumentRoot /var/www/userdomain.com/html
  ErrorLog /var/www/userdomain.com/logs/error_log
  LogFormat "%h %l %u %t \"%r\" %>s %b" common
  CustomLog /var/www/userdomain.com/logs/access_log
  ProxyPass /yourwebapp https://www.mydomain.com/yourwebapp
  ProxyPassReverse /yourwebapp https://www.mydomain.com/yourwebapp
</virtualHost>
share|improve this answer
    
Thanks Jason! Yes I am using apache front end with mod_jk (ajp) to route requests to tomcat. Can you tell me what other information you need regarding my application? I want to add domains dynamically, so that I don't have to restart apache every time I add a domain. How can I achieve this? –  satish May 10 '10 at 7:03
    
It's hard to know exactly what to suggest without knowing what your app does and what parts if any change from when a user accesses it from different domains. If its basically a static site then I think the suggestion above will work, but if content changes depending on what domain the user connects to, it may get harder. It will really depend on how your app does what it does and the different behaviour, if any, between accessing it via different domains. –  Jason Tan May 10 '10 at 10:37
    
The content is constant for a particular user. But for user to user, the content changes. Its just that i am giving different access points to the user to access his account on my site. My application is a java/jsp app, which fetches content from the mysql database depending on the userid and serves the content. Whether the request comes through www.userdomain.com or username.mydomain.com or www.mydomain.com?userid=xyz my application treats the request as www.mydomain.com?userid=xyz and fetches the content accordingly. Its just like if meetup.com allows the groups to have their own domains. –  satish May 10 '10 at 13:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.