Skip to main content
  1. Posts/

Lighttpd proxy to Tomcat

·459 words·3 mins·

It seems like lighttpd and Tomcat are at the forefront of what is ‘hot’ these days. If you don’t need the completeness of Apache on your server, you can use lighttpd to proxy to Tomcat, and it’s pretty simple. This how-to will show you how to install lighttpd, Tomcat, and the Java JRE. Once they’re installed it will also show you how to get lighttpd to use mod_proxy to connect to your Tomcat installation.

First, some downloading has to be done. Grab the latest lighttpd RPM from for your distribution. You will also need to pick up the latest version of Tomcat and the Java JRE.

Once all three of those are on the server, get them installed:

# rpm -Uvh lighttpd-1.3.16-1.2.el4.rf.i386.rpm
# tar xvzf apache-tomcat-6.0.10.tar.gz
# mv apache-tomcat-6.0.10 /usr/local/
# chmod +x jre-6u1-linux-i586.bin
# ./jre-6u1-linux-i586.bin
# mv jre1.6.0_01 /usr/local/

Before you can do much else, you will need to set up your JAVA_HOME and add JAVA_HOME/bin to your path. Open up /etc/profile and add the following before the export statement:

export JAVA_HOME

To make this change actually take effect, you will need to log out and become root again. Now, check that your JAVA_HOME is set:

# echo $JAVA_HOME

If the JAVA_HOME is not set up, check your /etc/profile again. If it’s set up, try starting Tomcat – there’s no need to set the $CATALINA_HOME, because Tomcat can figure it out on its own:

# /usr/local/apache-tomcat-6.0.10/bin/
Using CATALINA_BASE:   /usr/local/apache-tomcat-6.0.10
Using CATALINA_HOME:   /usr/local/apache-tomcat-6.0.10
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.10/temp
Using JRE_HOME:       /usr/local/jre1.6.0_01/

Try to connect to the server now on port 8080 and you should see a Tomcat default page. Now, go add a manager user to the $CATALINA_HOME/conf/tomcat-users.xml:

<role rolename="manager"/>
<user username="tomcat" password="password" roles="manager"/>

Restart Tomcat for the changes to take effect:

# /usr/local/apache-tomcat-6.0.10/bin/
# /usr/local/apache-tomcat-6.0.10/bin/

Tomcat is ready to go, so it’s time to configure lighttpd. Open the /etc/lighttpd/lighttpd.conf and activate mod_proxy by uncommenting it:

server.modules              = (
#                               "mod_rewrite",
#                               "mod_redirect",
#                               "mod_alias",
#                               "mod_cml",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
#                               "mod_fastcgi",
#                               "mod_simple_vhost",
#                               "mod_evhost",
#                               "mod_userdir",
#                               "mod_cgi",
#                               "mod_compress",
#                               "mod_ssi",
#                               "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",
                                "mod_accesslog" )

Drop to the bottom of the configuration file and add something like this, replacing your information as necessary:

$HTTP["host"] =~ "" {
        proxy.server = (
                "" => (
                        "tomcat" => (
                                "host" => "",
                                "port" => 8080,
                                "fix-redirects" => 1

Replace the IP address with a hostname or the correct IP for your server. This proxy directive makes lighttpd connect to Tomcat on the localhost on port 8080 whenever a request comes in on port 80 to lighttpd on the IP Start lighttpd now and try it yourself!

# /etc/init.d/lighttpd start