作者giive (lala)
看板Ruby
标题[心得] Lighttpd 跑 Rails and PHP 设定
时间Thu Sep 14 08:16:49 2006
这个网页是 lighttpd 单独跑 Rails 设定
http://lightyror.blogspot.com/2006/09/lighttpd-rails.html
这个网页是 Multi Domain 来跑 Rails and PHP 设定
http://lightyror.blogspot.com/2006/09/lighttpd-rails-domain.html
这个网页是 Single Domain 跑 Rails and PHP 设定
因为还有引用别人文章
所以就不在这里提了
http://lightyror.blogspot.com/2006/09/lighttpd-rails-domain_13.html
***警告***
因为我懒得学 ASCII
所以很多HTML标题效果,我都没有调整
如果你觉得下面的文章很难看的懂
麻烦请到网页上面看 *_*
至於这里的文章仅当作留下纪录给大家翻阅
*******
最简单的方式
其实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
Rails + PHP 的 lighttpd 设定档
Rails 跑在 Lighttpd 上面的设定一向不简单
尤其是可以同时跑 PHP 跟 Rails 的设定更是麻烦
下面我参考 Rails 内附的 lighttpd 修改出相关的设定档
我是使用 不同 domain 来区别 fastcgi 的设定
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" {
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,
)
)
)
}
--
lighty RoR 是一个介绍 lighttpd , SQLite , Ruby and Rails 的 Blog
http://lightyror.blogspot.com/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.230.100.104
※ 编辑: giive 来自: 61.230.100.104 (09/14 08:29)
※ 编辑: giive 来自: 61.230.100.104 (09/14 08:55)
※ 编辑: giive 来自: 61.230.100.104 (09/14 08:58)