How do I set up virtual hosting on Tomcat with Apache?

Serge Knystautas

[The Tomcat User's Guide has a section called "Configuring Virtual Hosting" at http://jakarta.apache.org/tomcat/jakarta-tomcat/src/doc/uguide/tomcat_ug.html. This document should also be in the distribution under the doc directory. -Alex]

You can configure your Apache server's virtual hosts to map to virtual hosts in a single Tomcat instance. Each virtual host would exist as a separate servlet context.

[For mod_jk instructions, see the user's guide. For mod_jserv...]

First configure Apache with mod_jserv, mapping the appropriate hostnames to Tomcat. Here is a sample from httpd.conf:
ApJServManual          on
ApJServSecretKey       DISABLED
ApJServMountCopy       on
ApJServLogLevel        notice

ApJServDefaultProtocol ajpv12
ApJServDefaultPort     8007
ApJServDefaultHost     localhost

AddType      text/jsp .jsp
AddHandler   jserv-servlet .jsp

NameVirtualHost 192.168.0.2

<VirtualHost 192.168.0.2>
    DocumentRoot /var/www/server1
    ServerName server1.lokitech.com
    ApJServMount /servlet /ROOT
    <Directory /var/www/server1/WEB-INF>
        Order allow,deny
        Deny from all
    </Directory>
</VirtualHost>

<VirtualHost 192.168.0.2>
    DocumentRoot /var/www/server2
    ServerName server2.lokitech.com
    ApJServMount /servlet /ROOT
    <Directory /var/www/server2/WEB-INF>
        Order allow,deny
        Deny from all
    </Directory>
</VirtualHost>

Second, configure Tomcat for virtual hosts. In your server.xml, you will wrap each servlet context in a <host>. Here is a sample from server.xml:

<Host name="server1.domain.com">
<Context path="" docBase="/var/www/server1" reloadable="true" debug="0" />
</Host>
<Host name="server2.domain.com">
<Context path="" docBase="/var/www/server1" reloadable="true" debug="0" />
</Host>

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact