Creating subdomains in tomcat

Status
Not open for further replies.

gopinath112

Active Member
471
2010
26
0
I am using tomcat 7 in my server and I like to create sub domain like m.mysite.com.So is there any procedure to follow ? I didn't find any thing in google.

Thankyou.
 
1 comment
You’ll need to create a virtual host for each subdomain in Apache configuration like:

Code:
<VirtualHost *:80>
Code:
[COLOR=#000000][FONT=Arial]ServerAdmin [EMAIL="webmaster@subdomain1.mydomain.com"]webmaster@subdomain1.mydomain.com[/EMAIL][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]DocumentRoot /www/subdomain1.mydomain.com[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]ServerName subdomain1.mydomain.com[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]ErrorLog logs/subdomain1.mydomain.com-host.example.com-error_log[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]CustomLog logs/subdomain1.mydomain.com-access_log common[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]</VirtualHost>[/FONT][/COLOR]

There is one problem though. If your solution requires folders creation, virtual host addition and apache restarts which does not look good to me. How would I deal with this problem is:

  1. Create a wildcard virtual host for “*.mydomain.com” so that all requests to subdomains go to this virtual host.
  2. Setup a rewrite rule for it to redirect all requests to one page, say index.jsp
  3. Write up a JSP page taking the hostname the user came to, searching the redirect URL into a storage by it, i.e. mysql db, and redirecting to it. This script will be the index.jsp script on the wildcard host.
If you use this way, you only need to setup the above once and then add the subdomains in to the storage which appears to be more flexible solution than creating subfolders and modifying Apache configuration.
 
Status
Not open for further replies.
Back
Top