在 Windows 平台使用 Apache2.2 和 Mongrel 运行 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 代码 ProxyRequests Off
BalancerMember localhost:3000 BalancerMember localhost:3001 ServerName xxx DocumentRoot d:/rubyproject/depot/public ProxyPass /images ! ProxyPass /stylesheets ! ProxyPass /javascripts ! ProxyPass / balancer://myCluster/ ProxyPassReverse / balancer://myCluster/ ProxyPreserveHost on myCluster 定义了群集中的每个 mongrel 应用服务器节点。 ProxyPass /images !指明该 URL 开 始的请求不代理给 Mongrel 群集,而由 Apache 自己处理。重起 Apache,然后打开浏览器访 问 xxx,检查配置是否正确。 至此, Windows Server 上面一个具备良好稳定性和性能的 Ruby on rails 生产环境就搭建好 在 了。 对于页面输出,还可以使用 mod_deflate 进行输出内容
压缩,以提高页面下载速度,这个就 留给大家自己配置了。 声明:ITeye 文章
版权属于作者,受法律保护。没有作者书面许可不得转载。