论坛首页 编程语言技术论坛

在Windows平台使用Apache2.2和Mongrel运行Ruby on Rails

浏览 69330 次
该帖已经被评为良好帖
作者 正文
   发表时间:2007-01-05  
Windows平台使用Apache2.2Mongrel运行Ruby on Rails
 
 
一、安装Ruby、rails、mongrel和Apache2.2
 
从rubyforge网站下载One-Click Ruby Install,运行安装程序,就安装好了ruby和rubygems。
 
运行命令:
gem install rails –y
gem install mongrel –y
gem install mongrel_service -y
安装好了rails和mongrel
 
从Apache网站下载Windows版本的Apache2.2,运行安装程序,就安装好了Apache2.2。
 
二、把Mongrel作为Services启动
 
mongrel_rails service::install -N depot -c d:\Rubyproject\depot -p 3000 –e production
-N指明服务名称,-d指明rails应用的目录,-p是mongrel监听的tcp端口,-e是启动模式为生产模式
 
这样打开控制面版|管理工具|服务,就可以发现增加了一项名为“depot”的服务,就可以通过控制面版来管理服务了。如果需要命令行启动和关闭该服务,那么:
mongrel_rails service::start -N depot
mongrel_rails service::stop -N depot
 
如果需要从服务中注销该项服务,那么:
mongrel_rails service::remove -N depot
 
如果需要安装多个mongrel实例,那么可以这样:
mongrel_rails service::install -N depot0 -c d:\Rubyproject\depot -p 3000 –e production
mongrel_rails service::install -N depot1 -c d:\Rubyproject\depot -p 3001 –e production
诸如此类。
 
三、配置Apache2.2
 
用编辑工具打开Apache2.2目录下面的conf/httpd.conf,需要取消如下模块的注释:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
如果你希望对页面输出使用压缩,也需要取消如下模块的注释:
LoadModule deflate_module modules/mod_deflate.so
 
然后按如下内容配置基于HTTP代理的负载均衡:
xml 代码
 
  1. ProxyRequests Off   
  2. <Proxy balancer://myCluster>  
  3.   BalancerMember http://localhost:3000   
  4.   BalancerMember http://localhost:3001   
  5. </Proxy>  
  6.   
  7. <VirtualHost *:80>  
  8.   ServerName www.xxx.com   
  9.   DocumentRoot d:/rubyproject/depot/public   
  10.   ProxyPass /images !   
  11.   ProxyPass /stylesheets !   
  12.   ProxyPass /javascripts !   
  13.   ProxyPass / balancer://myCluster/   
  14.   ProxyPassReverse / balancer://myCluster/   
  15.   ProxyPreserveHost on   
  16. </VirtualHost>  
 
myCluster定义了群集中的每个mongrel应用服务器节点。ProxyPass /images !指明该URL开始的请求不代理给Mongrel群集,而由Apache自己处理。重起Apache,然后打开浏览器访问www.xxx.com,检查配置是否正确。
 
至此,在Windows Server上面一个具备良好稳定性和性能的Ruby on rails生产环境就搭建好了。
 
对于页面输出,还可以使用mod_deflate进行输出内容压缩,以提高页面下载速度,这个就留给大家自己配置了。
   发表时间:2007-01-06  
不知道robin有没有对win和linux下的两种安装,ruby效率进行过测试?

1 请登录后投票
   发表时间:2007-01-06  
没有测试过,我也没有兴趣测试。
0 请登录后投票
   发表时间:2007-01-06  
Proxy
VirtualHost
要加关闭,目录自定

ProxyRequests Off   
<Proxy balancer://myCluster>  
  BalancerMember http://localhost:3000     
</Proxy>  
  
<VirtualHost *:80>  
  ServerName www.xxx.com   
  DocumentRoot D:\InstantRails\rails_apps\aa
  ProxyPass /images !   
  ProxyPass /stylesheets !   
  ProxyPass /javascripts !   
  ProxyPass / balancer://myCluster/   
  ProxyPassReverse / balancer://myCluster/   
  ProxyPreserveHost on   
</VirtualHost>  
0 请登录后投票
   发表时间:2007-01-06  
嘿嘿,开始以为会加速,但现在没什么感觉
0 请登录后投票
   发表时间:2007-01-06  
关闭标记被Rich Editor过滤掉了,重新用bbcode贴一下:

ProxyRequests Off    
<Proxy balancer://myCluster>   
  BalancerMember http://localhost:3000    
  BalancerMember http://localhost:3001    
</Proxy>   
   
<VirtualHost *:80>   
  ServerName www.xxx.com    
  DocumentRoot d:/rubyproject/depot/public    
  ProxyPass /images !    
  ProxyPass /stylesheets !    
  ProxyPass /javascripts !    
  ProxyPass / balancer://myCluster/    
  ProxyPassReverse / balancer://myCluster/    
  ProxyPreserveHost on    
</VirtualHost>  


cluster的作用不是加速单个请求的,是提高整体的负载能力的。
0 请登录后投票
   发表时间:2007-01-07  
觉得在 Windows 下用 InstantRails 最爽了,解压缩就可以用,Rails、MySQL、Apache、Mongrel 全都有了。
0 请登录后投票
   发表时间:2007-01-08  
^_^,还是502错误,问题出在哪里呢?我继续查找
0 请登录后投票
   发表时间:2007-01-10  
按照我的配置结果 apache 2.*在window平台下根本配置不成功!
在apache 1.3下倒可以,但不能实现群集!
0 请登录后投票
   发表时间:2007-01-12  
502 代理错误问题已经找到,原来是nod32搞的,汗...
停掉监视一切正常的,但还有个问题为什么1.3下面就可以呢?
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics