9/14/2006

lighttpd 跑 Rails 設定

最簡單的方式

其實Rails 自己就有附設定檔,如果你不想自己寫那麼多設定,只想用 lighttpd 跑 Rails。您首先要確定您這個 user 擁有可以使用 lighttpd 的權限 ,然後在 Rails 資料夾下打
ruby script/server
他應該就會直接使用 lighttpd,下面是啟動 lighttpd 正常的message
=> Booting lighttpd (use 'script/server webrick' to force WEBrick)
=> Rails application started on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)
如果出現下面的message,代表只有啟動 Webrick
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
那通常就是您這個 user 不可以使用 lighttpd 的權限
打入
ruby script/server lighttpd

這個指令強制使用 lighttpd ,用於 Debug 用途。並且會將 lighttpd config copy 一份到rails 資料匣下面的 conf/lighttpd.conf ,config 預設 port 是 3000,如果你想要直接用 port 80,可以到裡面把改成
server.port = 80

詳細的方式

Var 的部份
var.railsbasedir = '/rails/root/dir/'
這裡是設定 config 檔的變數,以後修改位置改這裡就好了

Server Port的部份

server.bind = "1.2.3.4"
server.port = 3000
Server.bind 就是server 的 ip,server.port 就是lighttpd listen 的 port。

Modules 的部份
server.modules = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi","mod_compress", "mod_expire" )
這裡是相關一定要enable的 Modules


其他設定的部份
# Ruby on Rails Config
server.error-handler-404 = "/dispatch.fcgi"
server.document-root = var.railsbasedir + "/public/"
server.errorlog = var.railsbasedir + "/log/lighttpd.error.log"
accesslog.filename = var.railsbasedir + "/log/lighttpd.access.log"

url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )

compress.filetype = ( "text/plain", "text/html", "text/css", "text/javascript" )
compress.cache-dir = var.railsbasedir + "/tmp/cache"

expire.url = ( "/favicon.ico" => "access 3 days",
"/images/" => "access 3 days",
"/stylesheets/" => "access 3 days",
"/javascripts/" => "access 3 days"
)

fastcgi.server = (
".fcgi" => ( "localhost" => (
"min-procs" => 1,
"max-procs" => 3,
"socket" => var.railsbasedir + "/tmp/sockets/fcgi.socket",
"bin-path" => var.railsbasedir + "/public/dispatch.fcgi",
"bin-environment" => ( "RAILS_ENV" => "development" )
)))

$HTTP["useragent"] =~ "^(.*MSIE.*)|(.*AppleWebKit.*)$" {
server.max-keep-alive-requests = 0
}

有幾個地方可以注意
  1. var.railsbasedir的部份只是因為以後搬目錄方便設定,其實那裡都可以用絕對路徑設定
  2. "min-procs" => 1, "max-procs" => 3 代表最少fastcgi process 一個,最多三個
  3. "bin-environment" => ( "RAILS_ENV" => "development" ) 代表現在 rails 是啟動 development 的環境,可以轉成 production 跟 test

沒有留言: