Rails Lighttpd Mongrel - OZJOY

来源:百度文库 编辑:神马文学网 时间:2024/05/06 02:33:04
Rails+Lighttpd+Mongrel ... by Kevin ... 3 月 18 天前,337 次点击
每次开始都会面临艰难和痛苦,然而这一切又是我们不得不做的
我们迫不得已需要改进我们的工作了,因为Rails对requests的处理问题上,它要求的是每次处理一个request,只有当当前的 request处理完毕之后,才进行下一个request的请求,这是比较可怕的,我曾经做过一个可以上传软件的网站,假定某用户上传了一本电子书,因为网络速度不快,他花了5分钟才完成了这个操作,也就是他的这个request将占用5分钟,同样的意思是,网站在5分钟内无法访问,这是可怕的。
什么是Mongrel?
一个快速的Web Server,速度快于WEBrick甚多
什么是Lighttpd?
用于转发request到a cluster of Mongrel
使用它们可以解决Rails在request上面出现的问题
下面我们开始安装Windows版本的Lighttpd了,下载地址是:http://www.kevinworthington.com:8181/?p=116,不过笔者写此文时时无法下载的。windows版本的lighttpd默认被安装在c:/lighttpd,这个安装位置是不能修改的
然后安装Mongrel,使用命令行:gem install mongrel –include-dependencies命令来安装的,安装的时候注意选择windows版本的,在rails app目录下面运行mongrel_rails start -p 4001,就可以开启Mongrel server,之前我有发表一片叫做《Mongrel---Faster Is Possible》的文章,注意除了安装Mongrel,还要安装service
刚从WEBrick转到Mongrel会感觉速度快了很多,使用-e production 开启 production environment
把Mongrel安装成为Windows服务:
mongrel_rails service::install -N MyApp_Dev -c C:\Rails\MyApp -p 4001 -e production
你可以设置成为自动,安装成为服务是很必要的,因为,你不可能每次都登录服务器,来运行你的server,即使你加到启动中,你也需要使用用户登录之后系统才可以自动启动
假如你想删除这个服务使用:
mongrel_rails service::remove -N MyApp_Dev
配置Lighttpd,配置port:
打开c:\lighttpd\etc\lighttpd.conf
取消 server.port = 81 前的注释,你也可以使用port:80
开启模块,其他模块不要乱开,会出问题
server.modules = ("mod_proxy",
"mod_rewrite",
"mod_accesslog",
"mod_alias" )
另外在这个配置文件末位加上:
proxy.debug = 0
proxy.balance = "fair"
proxy.server = ( "/" =>
(
( "host" => "127.0.0.1", "port" => 4001 ),
( "host" => "127.0.0.1", "port" => 4002 )
)
)
这里的port就是Mongrel server的port,启动Lighttpd使用命令:
c:\lighttpd\sbin\lighttpd.exe -D -f c:\lighttpd\etc\lighttpd.conf
通过http://localhost:81/ 就可以成功访问