Using Virtual Hosts on both Apache and Tomcat

There is now official documentation on configuring Apache and Tomcat with Confluence that covers this configuration in more detail.

Here's what you can do if you want to run Confluence and Jira on a single Tomcat instance behind an Apache server and you want to make them available at addresses like confluence.notatlassian.com and jira.notatlassian.com.

1. Set up virtual hosts in Apache:

<VirtualHost xxx.xxx.xxx.xxx>
  ServerName confluence.notatlassian.com
  ProxyPass / http://confluence.notatlassian.com:8080/
  ProxyPassReverse / http://confluence.notatlassian.com:8080/
</VirtualHost>

Note the use of confluence.notatlassian.com in the ProxyPass directives; if you use localhost, Tomcat won't be able to choose the correct virtual host.

2. Set up virtual hosts in Tomcat:
add this to $TOMCAT/conf/server.xml in the <Engine> section

<Host name="confluence.notatlassian.com" appBase="confluence"
  unpackWARs="true" autoDeploy="true"
  xmlValidation="false" xmlNamespaceAware="false">
    <Context path="" docBase="" debug="0"/>
</Host>

Labels

proxy proxy Delete
apache apache Delete
tomcat tomcat Delete
virtualhost virtualhost Delete
confluence confluence Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Dec 02, 2005

    Jay Proulx says:

    Note that you need to have mod_proxy compiled/installed in apache.  Likely ...

    Note that you need to have mod_proxy compiled/installed in apache.  Likely the ports should remain the same on the ProxyPass and ProxyPassReverse statements. 

    The URL in the Proxy* statements can also likely be directed to localhost, which means tomcat won't require any special extra configuration.  That is (of course), unless the tomcat instance is running on a different machine alltogether.

    See:
    Apache 2.0:

    Apache 1.3:

    1. Dec 02, 2005

      Eric Jain says:

      The URL in the Proxy* statements can also likely be directed to localhost That...

      The URL in the Proxy* statements can also likely be directed to localhost

      That's right – if you have separate Tomcat instances on different ports for each web application, or if you don't mind having the applications appear in subdirectories rather than at the top level of each subdomain (i.e. as virtual hosts).

  2. Dec 06, 2005

    Rob Kearey says:

    Does this apply to the standalone versions of Jira and Confluence? For example,...

    Does this apply to the standalone versions of Jira and Confluence?

    For example, I have a server, intranet.example.com, which has CNAMES of jira.example.com and confluence.example.com and virtual hosts set up for them.

    1. Dec 07, 2005

      Eric Jain says:

      If you have Jira and Confluence running on different ports only the first step a...

      If you have Jira and Confluence running on different ports only the first step applies. As Jay Proulx pointed out you can also use localhost in the Proxy* directives in that case. This was also described here.

  3. Apr 05, 2006

    Russell Warren says:

    This info is great... I should have looked here first, rather than spending hour...

    This info is great... I should have looked here first, rather than spending hours hunting through Apache info and forums!

    Anyway - for the case of using mod_proxy, has anybody experimented with the mode_proxy Cache settings (CacheRoot, CacheProxy, etc) to see if there is any performance increase? I'm leaving it out for now, but am curious.

    1. Apr 06, 2006

      Eric Jain says:

      Haven't tried this as in our case most requests are done by people who are logge...

      Haven't tried this as in our case most requests are done by people who are logged in; these requests couldn't be cached anyway.

  4. Apr 11, 2006

    Martin Cleaver says:

    I understand step 1 but can you please explain what step 2 does and how it works...

    I understand step 1 but can you please explain what step 2 does and how it works? Its not obvious.

    Thanks, M.

    1. Apr 11, 2006

      Russell Warren says:

      If it helps, I just recently set my personal license up (on WestHost) and it end...

      If it helps, I just recently set my personal license up (on WestHost) and it ended up that I didn't need to do any Tomcat configuration whatsoever. ie: Step 2 was not needed.

      I had initially tried messing with this, but it turned out that once mod_proxy was functioning all it took to work was to get the virtual host set up with a redirect to 8080:

      <VirtualHost *>
      ServerName wiki.mydomain.com
      ServerAlias www.wiki.mydomain.com
      ProxyPass / http://mydomain.com:8080/
      ProxyPassReverse / http://mydomain.com:8080/
      </VirtualHost>
      
  5. Apr 17, 2006

    Rob Kearey says:

    I'm running two confluence instances under Tomcat 5.5.12 - blah.com:8180/foo and...

    I'm running two confluence instances under Tomcat 5.5.12 - blah.com:8180/foo and blah.com:8180/bar.  I'd like to have them appear to the world as foo.com and bar.com, but this seems to be quite complicated. Any hints or tips on where to begin for this, or some sample config that I could steal?