操作
Lighttpd 上的 Ruby on Rails¶
启动 Rails 应用程序¶
在 lighttpd 1.4 中,您可以使用“bin-path”选项从 lighttpd 派生 FastCGI 后端;但建议为此使用 spawn-fcgi。
使用类似这样的方法与 daemontools 配合来监督您的 Rails 后端:(./run 脚本,您需要一个 public/dispatch.fcgi 文件;大多数 Rails 应用程序都提供此文件或可供您使用的示例)
#!/bin/sh # needs spawn-fcgi version >= 1.6 exec 2>&1 export RAILS_ENV=production export LANG=en_US.UTF-8 # www-data is the user lighty runs as exec /usr/bin/spawn-fcgi -s /var/run/lighttpd/rails-application.sock -n -U www-data -u rails-app-user -- /path/to/rails-application/public/dispatch.fcgi
Lighttpd 1.4¶
获取 cleanurl.lua;即使您使用其他方法进行派生,/path/to/rails-application/public/dispatch.fcgi 文件也必须存在(或者您可能需要设置“check-local”=>“disable”)。
$HTTP["host"] == "rails-app.example.org" {
server.document-root = "/path/to/rails-application/public/"
magnet.attract-physical-path-to = ( "/etc/lighttpd/cleanurl.lua" )
fastcgi.server = ( "dispatch.fcgi" =>
((
"socket" => "/var/run/lighttpd/rails-application.sock",
# if you don't use spawn-fcgi you may try this:
# "bin-path" => "/path/to/rails-application/public/dispatch.fcgi",
# "max-procs" => 1,
# "bin-environment" => (
# "RAILS_ENV" => "production",
# "LANG" => "en_US.UTF-8",
# ),
# "bin-copy-environment" => (
# "PATH",
# ),
))
)
}
在子目录中运行 Rails 应用程序¶
警告:并非所有 Rails 应用程序都支持此功能。
假设您想将博客放在 http://rails-app.example.org/blog,请尝试以下操作
$HTTP["host"] == "rails-app.example.org" {
$HTTP["url"] =~ "^/blog" {
alias.url = (
"/blog" => "/path/to/rails-application/public/",
)
server.document-root = "/path/to/rails-application/public/" # needed so cleanurl.lua finds the right dispatch.fcgi
magnet.attract-physical-path-to = ( "/etc/lighttpd/cleanurl.lua" )
fastcgi.server = ( "dispatch.fcgi" =>
((
"socket" => "/var/run/lighttpd/rails-application.sock",
"strip-request-uri" => "/blog",
))
)
}
}
并将此添加到您的 Rails 应用程序配置中,例如在 config/environments/production.rb 中
config.action_controller.relative_url_root = "/blog"
在 simple-vhost 环境中使用 RubyOnRails¶
假设:为了方便设置,您想使用 simple-vhost 但仍希望分离 Rails 安装
$HTTP["host"] == "ruby.example.org" {
server.document-root = "/var/www/site/public/"
fastcgi.server = ...
}
else {
simple-vhost.server-root = "/var/www/servers/"
simple-vhost.default-host = "www.example.org"
simple-vhost.document-root = "pages"
}