Talk:Lighttpd and FastCGI

From ArchWiki
Jump to: navigation, search

I tried to follow the guide (without the php part) but got errors on lighttpd startup:

The first one: 2006-07-22 01:02:08: (mod_fastcgi.c.1022) execve failed for: /usr/lib/ruby/gems/1.8/gems/rails-1.1.4/dispatches/dispatch.fcgi No such file or directory

I saw that permissions were not correct (root.root) at dispatches - dir. I set them to nobody.nobody at /usr/lib/ruby/gems/1.8/gems/rails-1.1.4/dispatches/. I still got that error and then checked the files at dispatches dir more carefully. Each had /usr/local/bin/ruby and I changed it to /usr/bin/ruby.

Then also added this line to dispatch.fcgi: require File.dirname(__FILE__) + "/../environments/boot.rb" and commented out the previous environments - one.

I also did this: touch /var/log/myapp_fcgi_crash.log

and then chown nobody.nobody /var/log/myapp_fcgi_crash.log

and edited the last line of dispatch.fcgi RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log'

This made it possible to start lighttpd without any errors

EDIT: still got 500 errors when tried to get into dispatch.fcgi - then found this page: http://www.pragmatically.net/articles/2006/02/11/using-lighttpd-for-rails-development. After created a new project and copied the mentioned files over and started the lighttpd with script/lighttpd, I managed to get to the project page that came through lighttpd. Just in case they might disappear - I copied the files here, too.

Here is the first one that should be coped to script/lighttpd:

============================== clip ==================================
  1. !/usr/bin/ruby

require 'optparse'

OPTIONS = {

 :port        => 8000,
 :ip          => "0.0.0.0",
 :daemon      => false,
 :environment => "development",
 :app_name    => "myapp",

}

ARGV.options do |opts|

 script_name = File.basename($0)
 opts.banner = "Usage: ruby #{script_name} [options]"
 opts.separator ""
 opts.on("-p", "--port=port", Integer,
         "Runs Rails on the specified port.",
         "Default: 3000") { |OPTIONS[:port]| }
 opts.on("-b", "--binding=ip", String,
         "Binds Rails to the specified ip.",
         "Default: 0.0.0.0") { |OPTIONS[:ip]| }
 opts.on("-e", "--environment=name", String,
         "Specifies the environment to run this server under (test/development/production).",
         "Default: development") { |OPTIONS[:environment]| }
 opts.on("-a", "--app-name=name", String,
         "Specifies the application name.",
         "Default: rails_app") { |OPTIONS[:environment]| }
 opts.on("-d", "--daemon",
         "Make lighttpd / Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
         ) { OPTIONS[:daemon] = true }
 opts.separator ""
 opts.on("-h", "--help",
         "Show this help message.") { puts opts; exit }
 opts.parse!

end

ENV["RAILS_ENV"] = OPTIONS[:environment] RAILS_ROOT = File.dirname(__FILE__) + "/../" LIGHTTPD_CONF_FILE = "/tmp/#{OPTIONS[:app_name]}_lighttpd.conf"

File.open("#{RAILS_ROOT}config/lighttpd.conf", "r") do |file|

       conf = file.read
 conf.gsub!(/PORT/, OPTIONS[:port].to_s)
 conf.gsub!(/BINDING/, OPTIONS[:ip])
 conf.gsub!(/RAILS_ROOT/, File.expand_path(RAILS_ROOT))
 conf.gsub!(/APP_NAME/, OPTIONS[:app_name])
 File.open(LIGHTTPD_CONF_FILE, "w") { |output| output.write(conf) }

end

CMD = "lighttpd -f #{LIGHTTPD_CONF_FILE}" CMD << " -D" unless OPTIONS[:daemon] puts CMD `#{CMD}`

===================================================================

and the config file (copy to ./config/lighttpd.conf at your project dir):

====================== clip ==========================================

server.port = PORT server.bind = "BINDING"

server.pid-file = "/tmp/APP_NAME_lighttpd.pid"

  1. server.event-handler = "freebsd-kqueue"

server.modules = ( "mod_rewrite", "mod_redirect", "mod_access", "mod_fastcgi", "mod_accesslog" )

server.document-root = "RAILS_ROOT/public/" server.indexfiles = ( "dispatch.fcgi", "index.html" ) accesslog.filename = "RAILS_ROOT/log/lighttpd_access.log" server.errorlog = "RAILS_ROOT/log/lighttpd_error.log" server.error-handler-404 = "/dispatch.fcgi"


        1. fastcgi module
    1. read fastcgi.txt for more info

fastcgi.server = (

 ".fcgi" => (
   "APP_NAME" => ( 
     "socket" => "/tmp/APP_NAME1.socket",
     "bin-path" => "RAILS_ROOT/public/dispatch.fcgi",
     "min-procs" => 1,
     "max_procs" => 2
   )
 )

)

  1. mimetype mapping

mimetype.assign = (

 ".rpm"          =>      "application/x-rpm",
 ".pdf"          =>      "application/pdf",
 ".sig"          =>      "application/pgp-signature",
 ".spl"          =>      "application/futuresplash",
 ".class"        =>      "application/octet-stream",
 ".ps"           =>      "application/postscript",
 ".torrent"      =>      "application/x-bittorrent",
 ".dvi"          =>      "application/x-dvi",
 ".gz"           =>      "application/x-gzip",
 ".pac"          =>      "application/x-ns-proxy-autoconfig",
 ".swf"          =>      "application/x-shockwave-flash",
 ".tar.gz"       =>      "application/x-tgz",
 ".tgz"          =>      "application/x-tgz",
 ".tar"          =>      "application/x-tar",
 ".zip"          =>      "application/zip",
 ".mp3"          =>      "audio/mpeg",
 ".m3u"          =>      "audio/x-mpegurl",
 ".wma"          =>      "audio/x-ms-wma",
 ".wax"          =>      "audio/x-ms-wax",
 ".ogg"          =>      "audio/x-wav",
 ".wav"          =>      "audio/x-wav",
 ".gif"          =>      "image/gif",
 ".jpg"          =>      "image/jpeg",
 ".jpeg"         =>      "image/jpeg",
 ".png"          =>      "image/png",
 ".xbm"          =>      "image/x-xbitmap",
 ".xpm"          =>      "image/x-xpixmap",
 ".xwd"          =>      "image/x-xwindowdump",
 ".css"          =>      "text/css",
 ".html"         =>      "text/html",
 ".htm"          =>      "text/html",
 ".js"           =>      "text/javascript",
 ".asc"          =>      "text/plain",
 ".c"            =>      "text/plain",
 ".conf"         =>      "text/plain",
 ".text"         =>      "text/plain",
 ".txt"          =>      "text/plain",
 ".dtd"          =>      "text/xml",
 ".xml"          =>      "text/xml",
 ".mpeg"         =>      "video/mpeg",
 ".mpg"          =>      "video/mpeg",
 ".mov"          =>      "video/quicktime",
 ".qt"           =>      "video/quicktime",
 ".avi"          =>      "video/x-msvideo",
 ".asf"          =>      "video/x-ms-asf",
 ".asx"          =>      "video/x-ms-asf",
 ".wmv"          =>      "video/x-ms-wmv",
 ".bz2"          =>      "application/x-bzip",
 ".tbz"          =>      "application/x-bzip-compressed-tar",
 ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
)
====================================================================

Merge with Lighttpd For Both SSL And Non-SSL

I think this article would benefit from being merged with "Lighttpd For Both SSL And Non-SSL" into a general Lighttpd article. --Xiol 07:00, 22 August 2008 (EDT)

Merging.

I vote that it can be merged. Since we can have a own page for Lighttpd.

Own page just for Lighttpd.

Why do we need several pages? Just have one for Lighttpd, and use sections.

Birger :)

I vote for this suggestion --Linopolus 05:37, 11 July 2009 (EDT)
I've marked this article for deletion since it is now entirely redundant with Lighttpd. Lighttpd for SSL and non-SSL should be merged with Lighttpd instead after its accuracy dispute is resolved. James Eder 13:47, 3 July 2011 (EDT)