Here are the important sections of my lighttpd.conf file,
with some comments added. I am using Gentoo but I don’t think
there is anything distro-specific here.
This config was pieced together from many examples. I’d love
to hear comments or suggestions if anyone has them.
One caveat: Initially I had trouble getting the rails
application to route properly. I traced the problem to
some of the rails code referenced in this ticket/patch:
http://dev.rubyonrails.org/ticket/1048
Removing the apache-specific condition in relative_url_root
fixed the problem. I haven’t been able to determine if this
is a problem in my setup or in rails itself.
-----------------------------------------start
###########################################################
###########################################################
lighttpd.conf file serving both PHP and Ruby on Rails
applications via fastcgi. This file is for lighttpd 1.4.7
#######################################################
General server config, see lighttpd docs for details.
var.logdir = “/var/log/lighttpd”
server.modules = (
“mod_rewrite”,
“mod_access”,
“mod_auth”,
“mod_accesslog”,
“mod_fastcgi”,
“mod_alias”
)
include “mime-types.conf”
server.username = “lighttpd”
server.groupname = “lighttpd”
server.pid-file = “/var/run/lighttpd.pid”
server.indexfiles = (“dispatch.fcgi”, “index.php”, “index.html”,
“index.htm”, “default.htm”)
server.tag = “lighttpd”
server.follow-symlink = “enable”
static-file.exclude-extensions = (“.php”, “.pl”, “.cgi”, “.fcgi”, “.rb”,
“.rhtml”)
url.access-deny = (“~”, “.inc”, “.conf”)
server.errorlog = var.logdir + “/error.log”
accesslog.filename = var.logdir + “/access.log”
########################################################
By default, display an empty website. Rules below will
override this setting. This may not be appropriate or
necessary for all sites.
server.document-root = “/var/www/empty”
########################################################
A common directory for all web roots (optional).
alias.url = (“/common/” => “/var/www/common/”)
############################################################
Main configuration. In this config, the root of the web
while an RoR application is available beneath the root at
$HTTP[“host”] =~ “the-site.com” {
Root of the php application.
server.document-root = “/var/www/phpapp”
Rewrite all requests to /rorapp to use dispatch.fcgi, except
static content. The rails app is in /var/www/rorapp. There is
a symlink from /var/www/phpapp/rorapp → /var/www/rorapp/public.
url.rewrite = (“^/rorapp/stylesheets/(.+)” =>
“/rorapp/stylesheets/$1”,
“^/rorapp/images/(.+)” => “/rorapp/images/$1”,
“^/rorapp/javascripts/(.+)” =>
“/rorapp/javascripts/$1”,
“^/rorapp/(.*)$” => “/rorapp/dispatch.fcgi”)
Fastcgi configuration. The PHP application is spawned externally
via spawn-fcgi, while the RoR application is spawned and monitored
using the rails command script/process/spinner.
PHP must be compiled with fastcgi support. PHP/spawn-fcgi will
handle multiple processes internally, you only need to specify
the base port number here. See the spawn-fcgi docs for more info.
For the rails app, you need to specify each port spawned by
the spinner/spawner. This example uses three handlers. You may
need to install the fcgi ruby gem as well.
fastcgi.server = ( “.php” =>
( “localhost” =>
(
“host” => “127.0.0.1”,
“port” => 1200
)
),
".fcgi" => (
"localhost" =>
(
"host" => "127.0.0.1",
"port" => 1220
),
(
"host" => "127.0.0.1",
"port" => 1221
),
(
"host" => "127.0.0.1",
"port" => 1222
)
)
)
}
################################################
SSL (optional). Specify the IP address of your
external interface here.
$SERVER[“socket”] == “172.16.0.1:443” {
ssl.engine = “enable”
ssl.pemfile = “/etc/lighttpd/ssl/the-site.com.pem”
ssl.ca-file = “/etc/lighttpd/ssl/the-site.com.ca”
}
###########################################################
Another web root is specified here. In my implementation
I have several of these serving different sites. This
is optional of course.
$HTTP[“host”] =~ “another-site.com” {
ssl.engine = “disable”
server.document-root = “/var/www/another-site”
}
---------------------------------------------end