本来在 GOOGLE的BLOGSPOT上搞了个BLOG,折腾了好几篇,
结果BLOGSPOT被盾了,实在是!@#$%^%&^&^&&
事先研究了很多相关的材料,本站很多总结。
先装RUBY,RAILS2.3等略过
装PCRE
# apt-get update
# apt-get install libpcre3 libpcre3-dev
然后安装zlib,先要安装一个ubuntu下的zlib,可以到http://www.zlib.net下载,我下载的是zlib-1.2.3。下载安装步骤如下:
$wget http://www.zlib.net/zlib-1.2.3.tar.gz
$tar -xvzf zlib-1.2.3.tar.gz
$cd zlib-1.2.3
$./configure
$make
$sudo make install
http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
都是直接
./configure
make
make install
然后下载lighttpd:
http://www.lighttpd.net/download/
tar xzvf lighttpd-1.4.13.tar.gz
cd lighttpd-1.4.13
./configure --prefix=/usr/local/lighttpd
configure完毕以后,会给出一个激活的模块和没有激活模块的清单,可以检查一下,是否自己需要的模块都已经激活,在enable的模块中一定要有“mod_rewrite”这一项,否则重新检查pcre是否安装
试验 Hello Word!
$ cd ~/mytst
$ ruby script/generate controller Say
$ vim app/controllers/say_controllers.rb
> class SayController < ApplicationController
> def hello
> end
> end
$ vim app/views/say/hello.html.erb
> <html>
> Hello Word!
> </html>
$ ruby script/server
http://localhost:3000/say/hello
四、安装 Ruby 的 FCGI 支持
由于ruby的fcgi支持库需要在编译的时候联接FCGI的系统库,因此我们需要先安装FCGI库,下载FCGI源代码发行包:
http://www.fastcgi.com/dist/
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:
http://rubyforge.org/projects/fcgi/
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
if 少文件 mkmf(LoadError) 需要安装ruby1.8-dev
sudo apt-get install ruby1.8-dev
配置 Lighttpd
cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
cp doc/rc.lighttpd /etc/init.d/lighttpd
如果你的Linux是ubuntu,那么需要自己创建启动脚本,lighttpd官方wiki上面已经给出来该脚本,地址在:
http://redmine.lighttpd.net/wiki/1/ScriptsUbuntu
最后变成 /etc/init.d/lighttpd 文件
然后修改/etc/init.d/lighttpd,modify
#PATH=/sbin:/bin:/usr/sbin:/usr/bin
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
#LIGHTY_DAEMON=/usr/sbin/lighttpd
LIGHTY_DAEMON=/usr/local/sbin/lighttpd
#FCGI_DAEMON="/usr/bin/spawn-fcgi"
FCGI_DAEMON="/usr/local/bin/spawn-fcgi"
chmod a+rx /etc/init.d/lighttpd
#chmod u+x lighttpd
In Debian / Ubuntu you use update-rc.d rather than chkconfig:
update-rc.d lighttpd defaults
mkdir /etc/lighttpd
cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
修改/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 = "/srv/www/htdocs/"
server.document-root = "/home/test/tstapp/mytst/public"
$HTTP["host"] == "127.0.0.1"{
server.document-root = "/home/test/tstapp/mytst/public"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.debug = 1
fastcgi.server = (
".fcgi" => (
"demo" => (
"min-procs" => 1,
"max-procs" => 5,
"socket" => "/var/run/lighttpd/rails.socket",
"bin-path" => "/home/test/tstapp/mytst/public/dispatch.fcgi",
"bin-environment" => ("RAILS_ENV" => "development")
)
)
)
}
建立目录 /var/run/lighttpd
在lighttpd的虚拟域配置里面有一项
server.error-handler-404 = "/dispatch.fcgi"
意思是当lighttpd找不到URL对应的硬盘文件,就会调用Rails的dispatch.fcgi去处理该URL请求,这也是 lighttpd访问Rails的主要方式,其性能比URL转发要快。如果你在配置文件里面忽略了这一行,lighttpd就会直接返回404错误,而不是交给Rails处理。
sudo /etc/init.d/lighttpd start
我的脚本弄的有点问题,启动不正常,通过下面命令启动的
sudo lighttpd -f /etc/lighttpd/lighttpd.conf start
最后发现 找不到 dispatch.fcgi 和 dispatch.rb!
原来官方blog的确切消息,3.0的铁定不支持CGI了。所以,建议转NGINX/mongrel 或者 passenger,现在这些更流行,用的人也更多。
引用
Removed: CGI Support
Rails 3 will not support direct CGI dispatching. This was deprecated in Rails 2.3, so it should be no surprise to anyone that it’s being removed entirely. If you need to use CGI for some reason, though, remember that it’s still supported through Rack.
http://weblog.rubyonrails.org/2009/4/17/this-week-in-edge-rails
太黑色幽默了,研究了几天 LIGHTTPD+FCGI,结果 以后没用了 :(((((((((((
不过 RAILS2.3 还没完全拿掉,只是 DEPRECATE
从以前项目中拷过来 dispatch.fcgi,dispatch.rb 和 dispatch.fcgi 三个文件 到PUBLIC目录下
1st 行RUBY路径改成本机对应路径
再启动 lighttpd 还是起作用的
http://127.0.0.1/say/hello
结果BLOGSPOT被盾了,实在是!@#$%^%&^&^&&
事先研究了很多相关的材料,本站很多总结。
先装RUBY,RAILS2.3等略过
装PCRE
# apt-get update
# apt-get install libpcre3 libpcre3-dev
然后安装zlib,先要安装一个ubuntu下的zlib,可以到http://www.zlib.net下载,我下载的是zlib-1.2.3。下载安装步骤如下:
$wget http://www.zlib.net/zlib-1.2.3.tar.gz
$tar -xvzf zlib-1.2.3.tar.gz
$cd zlib-1.2.3
$./configure
$make
$sudo make install
http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
都是直接
./configure
make
make install
然后下载lighttpd:
http://www.lighttpd.net/download/
tar xzvf lighttpd-1.4.13.tar.gz
cd lighttpd-1.4.13
./configure --prefix=/usr/local/lighttpd
configure完毕以后,会给出一个激活的模块和没有激活模块的清单,可以检查一下,是否自己需要的模块都已经激活,在enable的模块中一定要有“mod_rewrite”这一项,否则重新检查pcre是否安装
试验 Hello Word!
$ cd ~/mytst
$ ruby script/generate controller Say
$ vim app/controllers/say_controllers.rb
> class SayController < ApplicationController
> def hello
> end
> end
$ vim app/views/say/hello.html.erb
> <html>
> Hello Word!
> </html>
$ ruby script/server
http://localhost:3000/say/hello
四、安装 Ruby 的 FCGI 支持
由于ruby的fcgi支持库需要在编译的时候联接FCGI的系统库,因此我们需要先安装FCGI库,下载FCGI源代码发行包:
http://www.fastcgi.com/dist/
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:
http://rubyforge.org/projects/fcgi/
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
if 少文件 mkmf(LoadError) 需要安装ruby1.8-dev
sudo apt-get install ruby1.8-dev
配置 Lighttpd
cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
cp doc/rc.lighttpd /etc/init.d/lighttpd
如果你的Linux是ubuntu,那么需要自己创建启动脚本,lighttpd官方wiki上面已经给出来该脚本,地址在:
http://redmine.lighttpd.net/wiki/1/ScriptsUbuntu
最后变成 /etc/init.d/lighttpd 文件
然后修改/etc/init.d/lighttpd,modify
#PATH=/sbin:/bin:/usr/sbin:/usr/bin
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
#LIGHTY_DAEMON=/usr/sbin/lighttpd
LIGHTY_DAEMON=/usr/local/sbin/lighttpd
#FCGI_DAEMON="/usr/bin/spawn-fcgi"
FCGI_DAEMON="/usr/local/bin/spawn-fcgi"
chmod a+rx /etc/init.d/lighttpd
#chmod u+x lighttpd
In Debian / Ubuntu you use update-rc.d rather than chkconfig:
update-rc.d lighttpd defaults
mkdir /etc/lighttpd
cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
修改/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 = "/srv/www/htdocs/"
server.document-root = "/home/test/tstapp/mytst/public"
$HTTP["host"] == "127.0.0.1"{
server.document-root = "/home/test/tstapp/mytst/public"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.debug = 1
fastcgi.server = (
".fcgi" => (
"demo" => (
"min-procs" => 1,
"max-procs" => 5,
"socket" => "/var/run/lighttpd/rails.socket",
"bin-path" => "/home/test/tstapp/mytst/public/dispatch.fcgi",
"bin-environment" => ("RAILS_ENV" => "development")
)
)
)
}
建立目录 /var/run/lighttpd
在lighttpd的虚拟域配置里面有一项
server.error-handler-404 = "/dispatch.fcgi"
意思是当lighttpd找不到URL对应的硬盘文件,就会调用Rails的dispatch.fcgi去处理该URL请求,这也是 lighttpd访问Rails的主要方式,其性能比URL转发要快。如果你在配置文件里面忽略了这一行,lighttpd就会直接返回404错误,而不是交给Rails处理。
sudo /etc/init.d/lighttpd start
我的脚本弄的有点问题,启动不正常,通过下面命令启动的
sudo lighttpd -f /etc/lighttpd/lighttpd.conf start
最后发现 找不到 dispatch.fcgi 和 dispatch.rb!
原来官方blog的确切消息,3.0的铁定不支持CGI了。所以,建议转NGINX/mongrel 或者 passenger,现在这些更流行,用的人也更多。
引用
Removed: CGI Support
Rails 3 will not support direct CGI dispatching. This was deprecated in Rails 2.3, so it should be no surprise to anyone that it’s being removed entirely. If you need to use CGI for some reason, though, remember that it’s still supported through Rack.
http://weblog.rubyonrails.org/2009/4/17/this-week-in-edge-rails
太黑色幽默了,研究了几天 LIGHTTPD+FCGI,结果 以后没用了 :(((((((((((
不过 RAILS2.3 还没完全拿掉,只是 DEPRECATE
从以前项目中拷过来 dispatch.fcgi,dispatch.rb 和 dispatch.fcgi 三个文件 到PUBLIC目录下
1st 行RUBY路径改成本机对应路径
再启动 lighttpd 还是起作用的
http://127.0.0.1/say/hello