Project

General

Profile

Actions

LighttpdOnRails » History » Revision 11

« Previous | Revision 11/17 (diff) | Next »
stbuehler, 2009-04-03 21:36


Ruby on Rails with Lighttpd

Starting the rails application

In lighttpd 1.4 you have the option to spawn FastCGI backends from lighttpd with the "bin-path" option; but it is recommend to use spawn-fcgi for that.

Use something like this with daemontools to supervise your rails backends: (./run script, you need a public/dispatch.fcgi for this; most rails applications provide it or an example which you can use)

#!/bin/sh
# needs spawn-fcgi version >= 1.6

exec 2>&1

export RAILS_ENV=production
export LANG=en_US.UTF-8

# www-data is the user lighty runs as
exec /usr/bin/spawn-fcgi -s /var/run/lighttpd/rails-application.sock -n -U www-data -u rails-app-user -- /path/to/rails-application/public/dispatch.fcgi

Lighttpd 1.4

Get cleanurl.lua from http://nordisch.org./.

$HTTP["host"] == "rails-app.example.org" {
    server.document-root = "/path/to/rails-application/public/" 
    magnet.attract-physical-path-to = ( "/etc/lighttpd/cleanurl.lua" )

    fastcgi.server    = ( "dispatch.fcgi" =>
        ((
            "socket" => "/var/run/lighttpd/rails-application.sock",
# if you don't use spawn-fcgi you may try this:
#            "bin-path" => "/path/to/rails-application/public/dispatch.fcgi",
#            "max-procs" => 1,
#            "bin-environment" => (
#                "RAILS_ENV" => "production",
#                "LANG" => "en_US.UTF-8",
#            ),
#            "bin-copy-environment" => (
#                "PATH",
#            ),
        ))
    )
}

Lighttpd 1.5

Get cleanurl.lua from http://nordisch.org./.

$HTTP["host"] == "rails-app.example.org" {
    server.document-root = "/path/to/rails-application/public/" 
    magnet.attract-physical-path-to = ( "/etc/lighttpd/cleanurl.lua" )

    $HTTP["url"] == "/dispatch.fcgi" {
        proxy-core.backends = ( "unix:/var/run/lighttpd/rails-application.sock" )
        proxy-core.protocol = "fastcgi" 
        proxy-core.allow-x-sendfile = "enable" 
    }
}

Using RubyOnRails in a simple-vhost environment

Let's say: For an easy setup you want to use simple-vhost but still want to separate the rails-installation:

$HTTP["host"] == "ruby.example.org" {
    server.document-root = "/var/www/site/public/" 
    fastcgi.server = ...
}
else $HTTP["host"] =~ "" {
    simple-vhost.server-root = "/var/www/servers/" 
    simple-vhost.default-host = "www.example.org" 
    simple-vhost.document-root = "pages" 
}

Updated by stbuehler over 15 years ago · 11 revisions