最近一直在寻找Rails在Windows平台上服务器平台,Google一番,终于发现了Mongrel这个优秀的平台。
步骤如下:
1、安装完成Rails以后,生成一个Rails程序,目录在d:\ruby\mywork\ent
2、安装Mongrel
gem install mongrel –y
gem install mongrel_service -y
安装好了rails和mongrel
3、把Mongrel作为Services启动
mongrel_rails service::install -N ent -c d:\ruby\mywork\ent -p 3000 –e production
-N指明服务名称,-d指明rails应用的目录,-p是mongrel监听的tcp端口,-e是启动模式为生产模式
在命令行里面,运行会提示安装成功。
4、打开控制面板-》管理工具-》服务里面,会找到ent这个服务名称,ent就是前面第3不输入的步骤,启动这个服务就可以,当然可以设置为自动启动(确实情况下是手工启动)
5、服务的删除和停止
mongrel_rails service::stop -N ent
如果需要从服务中注销该项服务,那么:
mongrel_rails service::remove -N ent
如果需要安装多个mongrel实例,那么可以这样:
mongrel_rails service::install -N ent0 -c d:\ruby\mywork\ent -p 3000 –e production
mongrel_rails service::install -N ent1 -c d:\ruby\mywork\ent -p 3001 –e production
6、其实现在就可以用http://localhost:3000来访问Rails程序了。
7、可以用Apache的Proxy功能,来把向本机80的请求转发到3000端口,实现Rails的发布。
配置如下在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
最后加入:
ProxyRequests Off
<Proxy balancer://myCluster>
BalancerMember http://localhost:3000
BalancerMember http://localhost:3001
>
<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
>
诸如此类。