Friday February 25, 2005
In my previous lighttpd article I only briefly mentioned how to configure it once it was compiled and installed. But I don’t really think there’s much reason to go into detail with configuring lighttpd because it’s pretty straight-forward and the comments in the example `lighttpd.conf` explains the different options pretty well.
However, since Lighttpd is a lean mean fast-cgi serving machine I’ve starting using it locally for developing Rails applications. It simply feels slighty faster than Apache2 with fast-cgi and since Rails reloads all it’s lovely goodies when you’re running in development mode, I see no reason to spend time waiting for webrick or “normal cgi” whenever I reload the page.
The “system” I’m currently using for local development is that each Rails application get its own lighttpd.conf located in `$RAILS_ROOT/config`. Obviously this limits me when it comes to working on more than one Rails application at exactly the same time, but I don’t multitask that good anyway and since I have a certain amount of terminals open anyway, using the tabbed ones in iTerm in my case, whenever I’m working on a particular app (tailing logfiles, irb and such), so why not open another one for lighttpd while I’m there.
Anyway, to the Config Mobile!
My lighttpd.conf for each project looks like this (located in
UPDATE: Apparently there’s a bug in Apples kqeue, which causes system freezes on dual machines, I’ve experienced this myself. The fix is to use “select” as the event-handler.
server.port = 8080 server.bind = "127.0.0.1" server.event-handler = "freebsd-kqueue" # OR "select" if you're on a dual cpu mac server.modules = ( "mod_rewrite", "mod_fastcgi" ) server.document-root = "/Users/johan/railsapp/public" server.errorlog = "/Users/johan/railsapp/log/server.log" server.error-handler-404 = "/dispatch.fcgi" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 1, "max-procs" => 5, "socket" => "/tmp/railsapp.fcgi.socket", "bin-path" => "/Users/johan/railsapp/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "development" ) ) ) ) mimetype.assign = ( ".pdf" => "application/pdf", ".gif" => "image/gif", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".png" => "image/png", ".css" => "text/css", [...and many more...] )
That’s the bare minimum needed to get a fully functional Rails application development environment up and running that gets served by lighttpd, the above will most likely only work with Rails from 0.10.x and up since the error-handler stuff is what makes Routes happy.
I didn’t paste all of the mimetypes in there, you can grab those from the lighttpd.conf that ships with the lighttpd dist. Fact is, it works without defining the mimetypes for all my browsers except Camino, but I guess it’s always a good thing to make sure that files gets served the right way.
I then start lighttpd with either `lighttpd -D -f config/lighttpd.conf` or `lighttpd -f config/lighttpd.conf` depending on my mood (the -D switch makes it not go into the background; makes it easier to terminate without killall/PID hunting).
The README supplied with Rails also contains an example config for lighttpd which is pretty much the same as this one
That’s how I’m doing it right now, I guess there are better ways such as using the vhost facilities of lighttpd. But honestly I just can’t be bothered for local development on my box where i’m the only one accessing the webserver(s). I like to keep things simple and seperated.