Sunday, February 06, 2011

Multiple domains with tomcat behind apache

This is how you would host multiple domains/webapps on a single tomcat behind apache via mod-jk.

first setup tomcat behind apache

I am setting up a new domain called dogself.com:

in server.xml add this under last host:

<Host name="dogself.com"  appBase="webapps-dogself"
  unpackWARs="true" autoDeploy="true"
  xmlValidation="false" xmlNamespaceAware="false">
<alias>www.dogself.com<alias>
</Host> 
 
and also add another connector port:
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" /> 

create a webapps-dogself directory next to webapps and give it the same permissions

in your virtualhost apache config:
ServerName dogself.com 
JkMount  /* dogself 
 
in workers.properties add dogself worker to list:
worker.list=another,dogself

# Define dogself
worker.dogself.port=8010
worker.dogself.host=dogself.com
worker.dogself.type=ajp13 

If you want the manager app to work on the domain you need to:
mkdir /etc/tomcat6/Catalina/dogself.com 

and copy the manager.xml into it from /etc/tomcat6/Catalina/localhost

in /var/lib/tomcat6 create a webapps-dogself dir and give it 0775 perms and chown it to tomcat:tomcat

restart tomcat and apache

Troubleshooting:
if you get error:
worker dogself can't resolve tomcat address dogself.com
Check that your dns a/aaaa records point to your ip. Comment out the worker in workers.properties and see if you can get to the apache vhost.

if any of the domains seems to point to another domain, ie the war that is running on one domain is incorrect. check if you are in the www.domain and if you have aliased the www both in tomcat and in apache. if you dont alias the www correctly tomcat will send you the the defaultDomain as defined in server.xml

1 comment: