I recently setup lighttpd on my home server when I did a full wipe. Up until now it’s just been hosting the map for my Minecraft server (which I’ve been using Overviewer to generate). I’ve recently been working on some Java web apps on the side and I wanted to be able to access these over port 80.
In the past I’ve had some experience doing this with Apache’s HTTP server, but I’m pretty new to lighttpd still. It actually ended up being very easy to set this up for lighttpd, as you’ll see. I’m using Ubuntu 11.10 Server Edition for this tutorial.
Preparation
You’ll need to have lighttpd and jetty up and running already. This isn’t very hard as lighttpd runs fine out of the box on Ubuntu. Jetty, on the other hand, doesn’t start by default due to a configuration setting. Let’s fix that now.
Look for this line and change the value to 0:
# change to 0 to allow Jetty to start
NO_START=1
Now go to http://localhost:8080 (or whatever your server address may be) to make sure Jetty is running correctly. If so you can go ahead and deploy your war file to:
/usr/share/jetty/webapps
If all goes well you should be able to access your application over port 8080.
Configure mod_proxy
mod_proxy is very easy to setup. You’ll want to edit the module’s configuration file at:
/etc/lighttpd/conf-available/10-proxy.conf
and add the following lines:
1 2 3 4 5 6 7 8 | |
Obviously you’ll want to change the “PATH_TO_APP” to the path for your application on Jetty (it’s also advisable to leave off the trailing slash since doing so will allow URLs with and without the trailing slash to proxy correctly).
Also, notice the empty quotes on the third line: this means that all requests for that path will be passed to Jetty. If you want to restrict it to a certain file type, you can use something like “.jsp” instead.
Enable mod_proxy
Now that the configuration is complete, you’ll want to enable mod_proxy and reload lighttpd’s configuration. This can be done by executing the following commands:
sudo lighttpd-enable-mod proxy
sudo service lighttpd force-reload
All done! Now you should be able to access your Java web application over port 80.