| There is now official documentation on configuring Apache and Tomcat with Confluence that covers this configuration in more detail. |
This page contains brief notes from Turadg Aleahmad on how to run Tomcat instances as VirtualHosts behind Apache, so that both can share port 80, eg.:
http://issues.example.com/ http://docs.example.com/
This approach on this page makes use of mod_proxy. For mod_jk2, see Connect using Apache mod_jk2.
At my site we have JIRA and Confluence, both running "standalone". We also sometimes run a separate Tomcat for development on its standard port 8080. So I set up JIRA at port 38080 and Confluence at port 48080. (In server.xml I prefixed a 3 or 4 to each port.)
At this point, we had ugly urls like http://confluence.example.com:48080/homepage.action . I wanted something cleaner. I wanted to serve off port 80, but that was already bound by Apache which serves an array of VirtualHosts we use for development.
I messed with mod_jk2 but found it way too complicated, particularly when I tried to make it work with VirtualHosts. So I resorted to the much simpler mod_proxy.
I'm running RHEL 3 so I was able to make the new VHosts by simply dropping a file in /etc/httpd/conf.d. Here is such a file:
NameVirtualHost *:80 # docs <VirtualHost *:80> ServerName docs.example.com ProxyPass / http://localhost:48080/ ProxyPassReverse / http://localhost:48080/ </VirtualHost>
If you've been serving off another port (eg. 58080), you can make it redirect.
# redirect old Tomcat install Listen 0.0.0.0:48080 NameVirtualHost *:58080 <VirtualHost *:58080> ServerName docs.examples.com Redirect / http://docs.example.com/ </VirtualHost>
For apache2, you can use a vhost file like this and it will allow repond to jira.example.com on port 80.
NameVirtualHost *
<VirtualHost *>
ServerName jira.example.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ErrorLog /var/log/apache2/jira_error.log
LogLevel warn
CustomLog /var/log/apache2/jira_access.log combined
</VirtualHost>

Comments (6)
Jul 30, 2005
Michael Yoder says:
Excellent page, thank you. I tried mod_jk2 and wasted about a day beating my he...Excellent page, thank you. I tried mod_jk2 and wasted about a day beating my head against it trying to make it work. No luck.
One note: if your 'context' is something like /confluence (so the site would be at localhost:8080/confluence) then you'll have problems with ProxyPass:
This does not work, or at least I couldn't get it to work. I think apache was passing along the requests but Tomcat was getting confused, and the result was a near-infinite loop spewing log messages...
Another really cool side benefit is that Apache's log files will now have all the access logs because Apache is passing off every single request to JIRA/Confluence. Since you've got the logs you can run log analyzers on them, and presto: site usage statistics.
Apr 17, 2006
Rob Kearey says:
One note: if your 'context' is something like /confluence (so the site would be ...One note: if your 'context' is something like /confluence (so the site would be at localhost:8080/confluence) then you'll have problems with ProxyPass
I had the same issue. As I'm running two confluence instances under tomcat do I need to resort to [eep] Tomcat vhosts?
Jul 30, 2005
Nick Faiz says:
Hi Michael, I run an instance of Confluence at home, using Apache and reverse p...Hi Michael,
I run an instance of Confluence at home, using Apache and reverse proxying. Find a httpd.conf below which shows how to set up mod_proxy for URL rewriting, reverse proxying, etc.. It might be of use to you.
Note - I dont bother with virtual hosting. Loki is a name hardwired to localhost - just a box sitting in my study. I use dynamic DNS (dyndns) and port forwarding on my router to make certain loki receives all requests to port 80. It handles everything from there.
When at home, I access the wiki using loki/wiki. When elsewhere, I use a public DNS, e.g. http://foo.org/wiki.
As you can see, it maps requests for */wiki to the tomcat/wiki (which is Confluence) and also does the same for */blog to tomcat/blojsom . It also reverses the mapping and handles URL rewriting in HTTP responses:
995 <IfModule mod_proxy.c>
996 ProxyRequests Off
997 #
998 <Proxy *>
999 Order deny,allow
1000 Allow from all
1001 </Proxy>
1002
1003 ProxyPass /wiki http://loki:8080/wiki
1004 ProxyPassReverse /wiki http://loki:8080/wiki
1005
1006 ProxyHTMLURLMap http://loki:8080/wiki /wiki
1007
1008 <Location /wiki/>
1009 ProxyHTMLURLMap / /wiki/
1010 </Location>
1011
1012 ProxyPass /blog http://loki:8080/blojsom/blog/tfw
1013 ProxyPassReverse /blog http://loki:8080/blojsom/blog/tfw
1014
1015 ProxyHTMLURLMap http://loki:8080/blojsom/blog/tfw /blog
1016
1017 <Location /blog/>
1018 ProxyHTMLURLMap / /blog/
1019 </Location>
1020
1021 ProxyPass /blojsom http://loki:8080/blojsom
1022 ProxyPassReverse /blojsom http://loki:8080/blojsom
1023
1024 ProxyHTMLURLMap http://loki:8080/blojsom /blojsom
1025
1026 <Location /blojsom/>
1027 ProxyHTMLURLMap / /blojsom/
1028 </Location>
The base URL of Confluence is set to the domain name I use via dynamic DNS - I think I did this so that RSS URLs would point to the correct server. Everything runs well, although I have not tested extensively with it yet.
Cheers,
Nick
Dec 02, 2005
Eric Jain says:
Here's another solution if you want to run Confluence and Jira on a single Tomca...Here's another solution 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.
Feb 09, 2006
Terence Kearns says:
Great tip Nick. Solves my problem. You forgot to mention that you need mod_proxy...Great tip Nick. Solves my problem. You forgot to mention that you need mod_proxy_html or similar - which does not come bundled with the standard apache distro. You need this to get ProxyHTMLURLMap to work.
Feb 11, 2006
Larry Talley says:
I have documented my configuration which features Apache virtual host and Tomcat...I have documented my configuration which features Apache virtual host and Tomcat default application so that URLs of the form http://host.domain/ get a response from Confluence.