Ruby and Lighttpd/FastCGI

hi,
I'm trying to write a FastCGI script with Ruby and Lighttpd.

I'm using ruby-fcgi 0.8.6, ruby 1.8.2 and lighttpd 1.3.11 (Ubuntu-Linux).

I have setup lighttpd with the following parameters
fastcgi.server = (".rb" =>
                                ( "localhost" =>
                                  ( "socket" => "/tmp/rb-fastcgi.socket" )
                                )
                              )

I wrote a ruby script similar to
http://www.rubygarden.org/ruby?FCGIExternalServer

#!/usr/bin/ruby
FCGI_PURE_RUBY=true
require 'socket'
require 'cgi'
require 'fcgi'

socket = UNIXServer.new('/tmp/rb-fastcgi.socket')
class << socket
  alias :oldaccept :accept
  def accept
    [oldaccept, nil]
  end
end

FCGI::Server.new(socket).each_request do |request|
  Thread.start {
    request.out.print "Content-type: text/html\r\n"
    request.out.puts "<html><head><title>Foo</title></head><body><b>Yeah</b></body></html>"
    request.finish
  }
end

I start the script (as user www-data) and restart lighttpd.
But trying to access the script from a browser does not return any results.

lighttpd's errorlog is empty and the http connection is normal.

Any ideas?

Regards,
Rüdiger Sonderfeld <kingruedi@c-plusplus.de>

I always use lighttpd's spawn-fcgi tool for this -- skip the UnixServer
bit in your ruby code, and just do the FCGI.each loop.

Ari

···

On Sun, 2005-07-17 at 00:25 +0900, Rüdiger Sonderfeld wrote:

hi,
I'm trying to write a FastCGI script with Ruby and Lighttpd.

I'm using ruby-fcgi 0.8.6, ruby 1.8.2 and lighttpd 1.3.11 (Ubuntu-Linux).

I have setup lighttpd with the following parameters
fastcgi.server = (".rb" =>
                                ( "localhost" =>
                                  ( "socket" => "/tmp/rb-fastcgi.socket" )
                                )
                              )

Aredridel wrote:

I always use lighttpd's spawn-fcgi tool for this -- skip the UnixServer
bit in your ruby code, and just do the FCGI.each loop.

It seems to be a problem within the request code. Even with spawn-fcgi it did
not work until I used the CGI Interface

#!/usr/bin/ruby
require 'cgi'
require 'fcgi'

FCGI.each_cgi do |cgi|
  cgi.out("text/html") { "<b>Ruby FCGI</b>" }
end

Thanks a lot.

Regards,
Rüdiger Sonderfeld <kingruedi@c-plusplus.de>