Tomcat: Dynamic Virtual Hosts

24 views
Skip to first unread message

Mello

unread,
Oct 13, 2011, 10:15:35 AM10/13/11
to ctjug...@googlegroups.com
Hi Guys,

I am trying to figure out how to dynamically add persistent virtual
hosts or context paths within a host to tomcat(6/7) without using the
(host-)manager. The official tomcat docs warns against using context
containers inside the "<Host> tags" in the server.xml but I cannot get
it working otherwise. The example below is what I'm trying to do.

My Context Path Example:
---------------------------------------
When I create the following file
"$CATALINA_HOME/conf/Catalina/localhost/docs.xml" with the following
content (next 2 lines):
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/docs" docBase="/usr/share/tomcat7-docs/docs"
antiResourceLocking="false" />

This resource localhost/docs is never loaded even if I try to restart
the tomcat service. The manager frontend does not pick it up either.
The static solution is usually what I resort to:

Static Solution:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/docs" docBase="/usr/share/tomcat7-admin/manager"
antiResourceLocking="false" />
</Host>

The same goes for virtual hosts where I create the file
$CATALINA_HOME/conf/Catalina/dev.example.com/ROOT.xml the static
solution for the virtual host as shown below:
<Host name="dev.example.com" appBase="webapps"
unpackWARs="false" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="example-dev" />
</Host>

I have tried working with tomcat 7.0.19 and 6.0.24. I am very
frustrated, hoping that someone could shed some light on the matter.

Regards,
Mell Ozor

Brian Silberbauer

unread,
Oct 14, 2011, 2:33:09 AM10/14/11
to ctjug...@googlegroups.com
Doesn't the manager offer a REST based interface you can use?

> --
> You received this message because you are subscribed to the Google Groups "CTJUG Forum" group.
> To post to this group, send email to CTJUG...@googlegroups.com
> To unsubscribe from this group, send email to CTJUG-Forum...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
> For the ctjug home page see http://www.ctjug.org.za
> For jobs see http://jobs.gamatam.com/

--
Brian Silberbauer Software Consulting

 +27 (0)83 566 2705
 http://www.gamatam.com/

jobs site: http://jobs.gamatam.com/

Mark van Wyk

unread,
Oct 14, 2011, 4:01:51 AM10/14/11
to ctjug...@googlegroups.com
I use multiple <host/> tags with 2 contexts in each a ROOT and a manager.

Is this what you want?

Alternatively, MOD_JK works really great.


--
You received this message because you are subscribed to the Google Groups "CTJUG Forum" group.
To post to this group, send email to CTJUG...@googlegroups.com
To unsubscribe from this group, send email to CTJUG-Forum...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
For jobs see http://jobs.gamatam.com/



--
Mark van Wyk


Mobile: 082 831 9227
Landline: 021 789 1427

"Before printing this email, please consider the animals and eat less of them"

Willem Dreyer

unread,
Oct 15, 2011, 4:33:27 AM10/15/11
to ctjug...@googlegroups.com
Hi Mark,

The reason why I'm trying to avoid using context tags inside <host/> tags is because it does not allow you to change the paths dynamically. The wars I need to deploy takes 2minutes+. I want adjust the paths in the context path without rebooting the server. If I am able to do that I can deploy a new version of my war along side the old (active) version and the just rename the context path to use the newer version. Thus preventing the downtime.

Initially I used MOD_JK/MOD_Cluster to play around with HA. Right now I'm just using MOD_JK to with a single tomcat server. I have also grown fond of MOD_JK. I've got a feeling the problem I have could be related to configuration issues in tomcat, I'm using default ubuntu packages. I'll testing with tomcat downloaded straight from Apache. Sometimes when I stop and start tomcat service it shows the default site "webapps/ROOT/" for all my configured virtual hosts, then when I restart the server (not using stop and start) then my virtual host config work again (with no changes were made to config files). Again using the ubuntu packages.

I am trying to avoid the manager by all means. I'll let you know what the outcome is.

Regards,
Mell Ozor

James Mc Millan

unread,
Oct 15, 2011, 5:59:20 AM10/15/11
to ctjug...@googlegroups.com
Tomcat 7 has "Parallel deployments", allowing you to deploy a new version of your app without downtime:
http://www.tomcatexpert.com/blog/2011/05/31/parallel-deployment-tomcat-7

Would be interested to hear from anyone that's tried it out :-)
Reply all
Reply to author
Forward
0 new messages