The Camping Server for Lighttpd

  1. Install Lighttpd.
  2. Install FastCGI.
  3. Install ruby-fcgi
  4. Add to lighttpd.conf:
     server.port                 = 3045                                                                                                
     server.bind                 = "192.168.0.103"                                                                                     
     server.modules              = ( "mod_fastcgi" )                                                                                   
     server.document-root        = "/usr/local/www/data/examples/"                                                                     
     server.errorlog             = "/usr/local/www/data/examples/error.log"                                                            
                                                                                                                                        
     #### fastcgi module                                                                                                               
     fastcgi.server = ( "" => (                                                                                                        
       "localhost" => (                                                                                                                
         "socket" => "/tmp/camping-examples.socket",                                                                                   
         "bin-path" => "/usr/local/www/data/dispatch.rb",                                                                              
         "bin-environment" => ("FORCE_ROOT" => "1"),                                                                                   
         "allow-x-send-file" => "enable",
         "check-local" => "disable",                                                                                                   
         "max-procs" => 1 ) ) )  
    
    These server settings are just an example, change them to suit your needs. However, the FastCGI settings are very finnicky. In particular: mount your app at the empty string "" and add FORCE_ROOT to your environment when you do that.
  5. In dispatch.rb:
     #!ruby
     #!/usr/local/bin/ruby                                                                                           
     require 'rubygems'                                                                                                                
     require 'camping/fastcgi'                                                                                                         
     Camping::Models::Base.establish_connection :adapter => 'sqlite3',
       :database => "/tmp/camping.db"                                  
     Camping::FastCGI.serve("/usr/local/data/examples/")
    

Serving One File

The above setup will serve a whole directory, just like TheCampingServer. If you only want to serve one app (at the root) change the last line in dispatch.rb to point to a single file.

 #!ruby
 Camping::FastCGI.serve("/usr/local/data/examples/blog.rb")

Mounting at a Subdirectory

You can certainly mount your app at a subdirectory on the web server. But remove the FORCE_ROOT and be sure the subdirectory name has no closing slash. Lighttpd is very particular about that. Here, let's mount at /myapp.

 server.port                 = 3045                                                                                                
 server.bind                 = "192.168.0.103"                                                                                     
 server.modules              = ( "mod_fastcgi" )                                                                                   
 server.document-root        = "/usr/local/www/data/examples/"                                                                     
 server.errorlog             = "/usr/local/www/data/examples/error.log"                                                            
                                                                                                                                    
 #### fastcgi module                                                                                                               
 fastcgi.server = ( "/myapp" => (                                                                                               
   "localhost" => (                                                                                                                
     "socket" => "/tmp/camping-examples.socket",                                                                                   
     "bin-path" => "/usr/local/www/data/dispatch.rb",                                                                              
     "allow-x-send-file" => "enable",
     "check-local" => "disable",                                                                                                   
     "max-procs" => 1 ) ) )