Dk Instiki+lighttpd

category: Howto, Software

This howto works for every rails-application, but some lines are for Instiki only.

Example Configuration

This or something like, you setup:

# Change this, if you want:
# Path to instiki:
instiki_path = "/var/www/localhost/instiki"
# for http://example.org/instiki
instiki_url = "/instiki"

Next lines protect your instiki, that only authenticated persons can change pages. You needn’t add this to your config. It’s only for Instiki.

$HTTP["url"] =~ "^" + instiki_url + "/(create_web|[^/]*/(save|remove_orphaned_pages|edit_web))" {
  auth.backend = "ldap"
  auth.backend.ldap.hostname = "ldap.example.org"
  auth.backend.ldap.base-dn = "ou=People,dc=example,dc=org"
  auth.backend.ldap.filter = "(uid=$)"
  auth.backend.ldap.allow-empty-pw = "disable"
  auth.require = (
    "" => (
      "method" => "basic",
      "realm" => "Wiki",
      "require" => "valid-user"
    )
  )
}

This is the main part. Your setup above will be used, there’s nothing to change. ;)

$HTTP["url"] =~ "^" + instiki_url {
  alias.url = ( instiki_url + "/" => instiki_path + "/public/" )
  server.error-handler-404 = instiki_url + "/dispatch.fcgi"

  fastcgi.server = (
    ".fcgi" => (
      "localhost" => (
        "socket"   => instiki_path + "/tmp/lighttpd-fcgi.socket",
        "bin-path" => instiki_path + "/public/dispatch.fcgi",
        "bin-environment" => ( "RAILS_ENV" => "production" ),
        "min-procs" => 1,
        "max-procs" => 5,
        "idle-timeout" => 10,
      )
    )
  )
}

config/environment.rb

To this file config/environment.rb, you must append this:

module ActionController
  class AbstractRequest
    alias_method :orig_rel_url_root, :relative_url_root
    def relative_url_root
      if (@env['SCRIPT_NAME'] && /\/dispatch\.(fcgi|rb|cgi)$/ =~ @env['SCRIPT_NAME'])
        @env["SCRIPT_NAME"].to_s.sub(/\/dispatch\.(fcgi|rb|cgi)$/, '')
      else
        orig_rel_url_root
      end
    end
  end
end

That’s all.