Lighttpd 的 Rails and PHP 設定 (不同 Domain )
Rails 跑在 Lighttpd 上面的設定一向不簡單,尤其是可以同時跑 PHP 跟 Rails 的設定更是麻煩,下面我參考 Rails 內附的 lighttpd 修改出相關的設定檔。我是使用 不同 domain 來區別 fastcgi 的設定。
Var 的部份
var.railsbasedir = '/rails/root/dir/'
Modules 的部份
server.modules = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi", "mod_compress", "mod_expire" )
Virtual Host Rails 的部份
$HTTP["host"] == "rails.example.com" {
# 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" )
}
Virtual Host PHP 的部份
$HTTP["host"] == "php.example.com" {
# PHP mod_fastcgi config
server.document-root = "/php/doc/root/dir"
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"host" => "61.218.90.243",
"port" => 1026,
"bin-path" => "/usr/bin/php-cgi",
"min-procs" => 1,
"max-procs" => 1,
)
)
)
}
要注意的部份
有幾個地方可以微調
- Rails Domain 是 rails.example.com
- PHP Domain 是 php.example.com
Var 的部份
var.railsbasedir = '/rails/root/dir/'
Modules 的部份
server.modules = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi", "mod_compress", "mod_expire" )
Virtual Host Rails 的部份
$HTTP["host"] == "rails.example.com" {
# 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" )
}
Virtual Host PHP 的部份
$HTTP["host"] == "php.example.com" {
# PHP mod_fastcgi config
server.document-root = "/php/doc/root/dir"
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"host" => "61.218.90.243",
"port" => 1026,
"bin-path" => "/usr/bin/php-cgi",
"min-procs" => 1,
"max-procs" => 1,
)
)
)
}
要注意的部份
有幾個地方可以微調
- var.railsbasedir 填入你的 rails 的 base dir
- "min-procs" => 1, "max-procs" => 3 代表最少fastcgi process 一個,最多三個
- "bin-environment" => ( "RAILS_ENV" => "development" ) 代表現在 rails 是啟動 development 的環境,可以轉成 production 跟 test
沒有留言:
張貼留言