Wednesday, December 9, 2009

Using Apache with mod_proxy

This page describes how to integrate Confluence into an Apache website, using mod_proxy. There are some common situations where you might do this:

* You have an existing Apache-based website, and want to add Confluence to the mix (eg.
* You have two or more Java applications, each running in their own application server on different ports, eg. http://localhost:8080/confluence and http://localhost:8081/jira. By setting up Apache with mod_proxy, you can have both available on the regular HTTP port (80), eg. at and If you are running JIRA and Confluence, we recommend this setup. It allows each app to be restarted, managed and debugged separately.

This page describes how to configure mod_proxy. We describe two options:

* If you want a URL like, go to the simple configuration.
* If you want a URL like, go to the complex configuration.

Simple configuration
Set the context path

First, set your Confluence application path (the part after hostname and port) correctly. Say you want Confluence available at, and you currently have it running at http://localhost:8080/. The first step is to get Confluence available at http://localhost:8080/confluence/.

To do this in Tomcat (bundled with Confluence), edit conf/server.xml, locate the "Context" definition:

and change it to:

Then restart Confluence, and ensure you can access it at http://localhost:8080/confluence/
Configure mod_proxy

Now enable mod_proxy in Apache, and proxy requests to the application server by adding the example below to your Apache httpd.conf (note: the files may be different on your system; the JIRA docs describe the process for Ubuntu/Debian layout):
01.# Put this after the other LoadModule directives
02.LoadModule proxy_module /usr/lib/apache2/modules/
03.LoadModule proxy_http_module /usr/lib/apache2/modules/
05.# Put this in the main section of your configuration (or desired virtual host, if using Apache virtual hosts)
06.ProxyRequests Off
07.ProxyPreserveHost On
10. Order deny,allow
11. Allow from all

14.ProxyPass /confluence http://localhost:8080/confluence
15.ProxyPassReverse /confluence http://localhost:8080/confluence
17. Order allow,deny
18. Allow from all

Note to Windows Users

It is recommended that you specify the absolute path to the and files.
Set the URL for redirection

You will need to modify the server.xml file in your tomcat's conf directory and set the URL for redirection.

Locate this code segment

And append the following segment:

Replace with the URL you wish to be redirected to.

Complex configuration

A complex configuration involves using the mod_proxy_html filter to modify the proxied content en-route. This is required if the Confluence path differs between Apache and the application server. For example:
Externally accessible (Apache) URL
Application server URL

Notice that the application path in the URL is different in each. On Apache, the path is /, and on the application server the path is /confluence.
For this configuration, you need to install the mod_proxy_html module, which is not included in the standard Apache distribution.

Alternative solutions are discussed below.
01.# Put this after the other LoadModule directives
02.LoadModule proxy_module modules/
03.LoadModule proxy_http_module modules/
04.LoadModule proxy_html_module modules/
07. ServerName
09. # Put this in the main section of your configuration (or desired virtual host, if using Apache virtual hosts)
10. ProxyRequests Off
11. ProxyPreserveHost On
14. Order deny,allow
15. Allow from all

18. ProxyPass /
19. ProxyPassReverse /
21. ProxyHTMLURLMap / /confluence/
24. Order allow,deny
25. Allow from all


The ProxyHTMLURLMap configuration can become more complex if you have multiple applications running under this configuration. The mapping should also be placed in a Location block if the web server URL is a subdirectory and not on a virtual host. The Apache Week tutorial has more information how to do this.
More information

* The mod_proxy_html site has documentation and examples on the use of this module in the complex configuration.
* Apache Week has a tutorial that deals with a complex situation involving two applications and ProxyHTMLURLMap.
* Using Apache with virtual hosts and mod_proxy shows how to configure the special case where you want JIRA and Confluence running on separate application servers on virtual host subdomains.


If Tomcat is your application server, you have two options:

* use mod_jk to send the requests to Tomcat
* use Tomcat's virtual hosts to make your Confluence application directory the same on the app server and the web server, removing the need for the URL mapping.

If your application server has an AJP connector, you can:

* use mod_jk to send the requests to your application server.

No comments:

Post a Comment

tag ur valuable ideas below