ErikDaRed

Bliggity Blog

Lighttpd + Jetty Using Mod_proxy

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
$HTTP["url"] =~ "^/PATH_TO_APP" {
  proxy.server = (
    "" => ((
      "host" => "127.0.0.1",
      "port" => 8080
    ))
  )
}

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.

Getting Started With Octopress on Ubuntu 11.10

I thought I’d write up a little how-to on setting up Octopress on Ubuntu 11.10, since I ran into some issues on a fresh install.

Install RVM

RVM is a version manager for Ruby, more information here

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

Add RVM to your shell

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
source ~/.bash_profile

Install Ruby 1.9.2

Install some dependencies first:

rvm pkg install zlib
rvm pkg install openssl

I had some issues with ruby not finding openssl, for this reason we’re going to use the version that was just installed to your rvm path.

Install Ruby:

rvm install 1.9.2 --with-openssl-dir=$rvm_path/usr
rvm rubygems latest  # This will make sure rubygems is the latest version
rvm use 1.9.2

Setup Octopress

git clone git://github.com/imathis/octopress.git octopress
cd octopress    # If you use RVM, You'll be asked if you trust the .rvmrc file (say yes).
ruby --version  # Should report Ruby 1.9.2

Install dependencies for Octopress

gem install bundler
bundle install

Install Octopress with default settings

rake install

Configure Octopress

Nothing special required here, just follow the Official Docs.

All Finished!

Everything should be working just fine now. Go ahead and follow the instructions here to make your first post.

Hello World

Hi there! I’m attempting at setting up my site again so I can blog about stuff that I’m doing and to share other interesting things.

I’m using Octopress, you should check it out!