Ubuntu 12.04 Mod Proxy Install and Configuration

A common task you need to perform when you first install JBoss, Tomcat, WebSphere, or some other Java Application Server is to create a reverse proxy. This channels incoming traffic from the usual HTTP port 80 to the usual JBoss port 8080 (or 9080 if you’re on WebSphere for example). This is how to do it.

Assumptions

1. You’ve got Ubuntu 12.04 up and running
2. You’ve already installed Apache
3. You have root access (preferably through sudo)

Procedure

1. Install required packages

sudo apt-get install libapache2-mod-proxy-html
sudo apt-get install libxml2-dev

2. Create symbolic links to enable mod proxy in Apache

cd /etc/apache/mods-enabled
sudo ln -s ../mods-available/proxy_http.load .
sudo ln -s ../mods-available/proxy.load .
sudo ln -s ../mods-available/headers.load .

3. Load libxml2.so by opening /etc/apache2/mods-enabled/proxy_html.conf and add the LoadFile line as shown below

# Configuration example.
#
# First, to load the module with its prerequisites
#
# For Unix-family systems:
# LoadFile /usr/lib/libxml2.so
# LoadModule proxy_html_module modules/mod_proxy_html.so
#
LoadFile /usr/lib/x86_64-linux-gnu/libxml2.so
...

4. Load /etc/apache2/sites-enabled/000-default to configure the proxy. Add the following:

# This excludes this directory from the proxy. Content in this directory will be loaded through Apache instead of redirecting the request to port 8080.
ProxyPassMatch ^/directory_with_files_served_from_apache(.*)$ !

# This redirects everything except the above exceptions to JBoss.
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Make sure this code is outside of tags. Generally, these lines should be part of the VirtualHost tag and not part of any child tags.

5. Restart Apache

sudo /etc/init.d/apache2 restart

Sources

http://knowledge-republic.com/CRM/2012/05/ubuntu-12-04-missing-libxml2-so-2-file-mod-security2/

Apache mod_proxy in Ubuntu

3 thoughts on “Ubuntu 12.04 Mod Proxy Install and Configuration

  1. Major Thanks! Have been trying to save data from OpenLayers -> GeoServer -> PostGIS for days now and thanks to your excellant post here, I finally succeeded.

    I did, however, find a couple of bugs in your post. First, this line:

    cd /etc/apache/mods-enabled

    should be:

    cd /etc/apache2/mods-enabled

    (i.e. apache2 not just apache).

    Also, I found that I had to define:

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

    as:

    ProxyPass /dir http://localhost:8080/
    ProxyPassReverse /dir http://localhost:8080/

    where ‘/dir’ is ANY directory name OTHER than ‘/’. This is where the ‘default’ address should reside. This was the only way that I could get both 8080 and 8081 to work with this code. Other than that, Fantastic. Thank You!

    Larry

Leave a comment