开发环境:Linux version 2.6.18-6-686 (Debian 2.6.18.dfsg.1-24)
gcc version 4.1.2 20061115 (Debian 4.1.1-21)
mysql
ruby 1.8.7 [i686-linux]
rails 2.3.2
步骤:(引用: http://www.iteye.com/topic/43228?page=1 )
1.安装 Ruby 的 FCGI 支持
由于ruby的fcgi支持库需要在编译的时候联接FCGI的系统库,因此我们需要先安装FCGI库,下载FCGI源代码发行包:
tar xzvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure --prefix=/usr/local/fcgi
make && make install
同样,将fcgi安装在自己指定的目录下,而不是默认的/usr/local,避免多个软件混在一起。
然后就可以安装ruby的fcgi支持库了,下载ruby-fcgi-0.8.7.tar.gz:
tar xzvf ruby-fcgi-0.8.7.tar.gz
cd ruby-fcgi-0.8.7
ruby install.rb config -- --with-fcgi-include=/usr/local/fcgi/include --with-fcgi-lib=/usr/local/fcgi/lib
ruby install.rb setup
ruby install.rb install
2. 安装 Lighttpd
在安装lighttpd之前,应该确认操作系统已经安装pcre,即Perl兼容的规则表达式库:
rpm –qa |grep pcre
如果没有,请从Linux安装光盘里面安装。
也可单独安装,下载pcre-7.9.tar.gz (附件)
tar xzvf pcre-7.9.tar.gz
cd pcre-7.9
./configure --prefix=/usr/local/
pcre
make && make install
然后下载lighttpd:
tar xzvf lighttpd-1.4.13.tar.gz
cd lighttpd-1.4.13
./configure --prefix=/usr/local/lighttpd
configure完毕以后,会给出一个激活的模块和没有激活模块的清单,可以检查一下,是否自己需要的模块都已经激活,在enable的模块中一定要有“mod_rewrite”这一项,否则重新检查pcre是否安装。然后编译安装:
make && make install
编译后配置:
cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
mkdir /etc/lighttpd
cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
如果你的Linux是RedHat/CentOS,那么:
cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd
如果你的Linux是SuSE,那么:
cp doc/rc.lighttpd /etc/init.d/lighttpd
其他Linux发行版本可以自行参考该文件内容进行修改。然后修改/etc/init.d/lighttpd,把
LIGHTTPD_BIN=/usr/sbin/lighttpd
改为
LIGHTTPD_BIN=/usr/local/lighttpd/sbin/lighttpd
此脚本用来控制lighttpd的启动关闭和重起:
/etc/init.d/lighttpd start
/etc/init.d/lighttpd stop
/etc/init.d/lighttpd restart
3.配置Lighttpd
server.document-root = "/execute/ror" #我的工程目录,rails应用为B2bM
server.errorlog = "/execute/ror/B2bM/log/lighttpd/error.log" # 要在../ B2bM/log/ 下手动创建相应的文件夹 lighttpd
index-file.names = ( "index.php", "index.html", "index.htm", "default.htm", "dispatch.fcgi" )
accesslog.filename = "/execute/ror/B2bM/log/lighttpd/access.log"
修改/etc/lighttpd/lighttpd.conf
1)server.modules
取消需要用到模块的注释,mod_rewrite,mod_access,mod_fastcgi,mod_simple_vhost,mod_cgi,mod_compress,mod_accesslog是一般需要用到的。
2)server.document-root, server.error-log,accesslog.filename 需要指定相应的目录
server.document-root = "/execute/ror" #我的工程目录,rails应用为B2bM
server.errorlog = "/execute/ror/B2bM/log/lighttpd/error.log" # 要在../ B2bM/log/ 下手动创建相应的文件夹 lighttpd
index-file.names = ( "index.php", "index.html", "index.htm", "default.htm", "dispatch.fcgi" )
accesslog.filename = "/execute/ror/B2bM/log/lighttpd/access.log"
server.port = 8000 #默认为80
4)静态文件压缩
compress.cache-dir = "/tmp/lighttpd/cache/compress" #要在/ tmp/ 下手动创建相应的文件夹 lighttpd/cache/compress
compress.filetype = ("text/plain", "text/html","text/javascript","text/css")
可以指定某些静态资源类型使用压缩方式传输,节省带宽,对于大量AJAX应用来说,可以极大提高页面加载速度。
5)配置ruby on rails
最简单的配置如下:
$HTTP["host"] == "vip.xxxx.cn" {
server.document-root = "/execute/ror/B2bM/public" #我的rails应用目录
server.error-handler-404 = "/dispatch.fcgi"
url.rewrite = ( #ulr重写规则
"^/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9%]+)\??([\-_a-zA-Z0-9=&%]*)$" => "/dispatch.fcgi?controller=$1&action=$2&id=$3&$4",
"^/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9]+)/?\??([\-_a-zA-Z0-9=&%]*)$" => "/dispatch.fcgi?controller=$1&action=$2&$3",
"^/([\-_a-zA-Z0-9]+)/?\??([\-_a-zA-Z0-9=&%]*)$" => "/dispatch.fcgi?controller=$1&action=index&$2" #,
)
fastcgi.server = (".fcgi" =>
("localhost" =>
("min-procs" => 2,
"max-procs" => 2,
"socket" => "/execute/ror/B2bM/tmp/lighttpd/socket/rails.socket", #要../ B2bM/tmp/ 下手动创建相应的文件夹lighttpd/socket/
"bin-path" => "/execute/ror/B2bM/public/dispatch.fcgi",
"bin-environment" => ("RAILS_ENV" => "production") #development production #运行环境,将产生相应的log (development.log /production.log)—— 这也是开发过程中查找错误原因的重要文件
)
)
)
}
server.document-root = "/execute/ror/B2bM/public" #我的rails应用目录
server.error-handler-404 = "/dispatch.fcgi"
url.rewrite = ( #ulr重写规则
"^/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9%]+)\??([\-_a-zA-Z0-9=&%]*)$" => "/dispatch.fcgi?controller=$1&action=$2&id=$3&$4",
"^/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9]+)/?\??([\-_a-zA-Z0-9=&%]*)$" => "/dispatch.fcgi?controller=$1&action=$2&$3",
"^/([\-_a-zA-Z0-9]+)/?\??([\-_a-zA-Z0-9=&%]*)$" => "/dispatch.fcgi?controller=$1&action=index&$2" #,
)
fastcgi.server = (".fcgi" =>
("localhost" =>
("min-procs" => 2,
"max-procs" => 2,
"socket" => "/execute/ror/B2bM/tmp/lighttpd/socket/rails.socket", #要../ B2bM/tmp/ 下手动创建相应的文件夹lighttpd/socket/
"bin-path" => "/execute/ror/B2bM/public/dispatch.fcgi",
"bin-environment" => ("RAILS_ENV" => "production") #development production #运行环境,将产生相应的log (development.log /production.log)—— 这也是开发过程中查找错误原因的重要文件
)
)
)
}
说明:以上手动创建的文件夹,其目录均可自行指定,只要lighttpd能找到这些文件路径(否则,将出错)
OK,配置完毕
如果运行时出错信息与cache有关可能还要安装一个gem: gem install memcache-client
如果是
dispatch.fcgi没启动,可能是权限问题,进入 相应目录(
/execute/ror/B2bM/public )执行
chmod 755 dispatch.fcgi 试试
其它错误原因查看
../
development.log /production.log 信息,部分常见错误的解决方案参考: http://www.iteye.com/topic/168989