Howto Rails

lighttpd config

See mod_core for the core.cached_html action.

setup {
    module_load ( "mod_expire", "mod_fastcgi", "mod_vhost", "mod_lua" );
    lua.plugin "core.lua";

var.vhosts = [];

# ...

var.vhosts = var.vhosts + [
    "" => {
        docroot "/var/www/servers/";
        index ("index.html");

                # looks for cached pages (with '.html' appended to the url), but only if the file for
                # the original url doesn't exists and doesn't end with '.html' (in the first case we already have a file,
                # in the second case we don't want to append another '.html' - if a file exists for the url we will still find it)
                # remove it if your rails app doesn't cache files, or modify it to look somewhere else (depending on your rails application).

        # deliver static files directly, forward everything else to the rails application
        if physical.is_file {
            header.add ("X-cleanurl", "hit");
        } else {
            header.add ("X-cleanurl", "miss");
            fastcgi "unix:/var/run/lighttpd/sockets/";

        if req.path =~ "\.(png|css|gif)$" {
            expire "access 1 week";

# ... var.vhosts;

spawn rails application

Simple ./run script to spawn rails applications with spawn-fcgi and runit/daemontools:


exec 2>&1

RAILS_ENV="production" \
exec /usr/bin/spawn-fcgi -n -s /var/run/lighttpd/sockets/ -u www-default -U www-data -- /var/www/servers/


Obviously you need a dispatch.fcgi FastCGI handler, if you don't have one, just try this one:

#!/usr/bin/env ruby

require File.dirname(__FILE__) + "/../config/environment" 
require 'fcgi_handler'


Updated by stbuehler about 5 years ago · 11 revisions