---
title: "在Windows下面用Mongrel作为Rails服务器平台"
author: "gm8pleasure"
date: "2007-06-25T07:34:14Z"
tags: ["C#", "Rails", "Ruby", "Windows", "应用服务器"]
slug: "windows-mongrel-rails"
draft: false
lastmod: "2007-06-25T07:34:14Z"
id: 94110
url: "https://pleasure.iteye.com/blog/94110"
---

最近一直在寻找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](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   

&lt;Proxy balancer://myCluster&gt;

  BalancerMember http://localhost:3000   

  BalancerMember http://localhost:3001   

&gt;

 

&lt;VirtualHost \*:80&gt;

  ServerName www.xxx.com   

  DocumentRoot d:/rubyproject/depot/public   

  ProxyPass /images !   

  ProxyPass /stylesheets !   

  ProxyPass /javascripts !   

  ProxyPass / balancer://myCluster/   

  ProxyPassReverse / balancer://myCluster/   

  ProxyPreserveHost on   

&gt;

诸如此类。

del.icio.us 标记: [rails](http://del.icio.us/popular/rails), [mongrel](http://del.icio.us/popular/mongrel)

![](http://c.services.spaces.live.com/CollectionWebService/c.gif?space=pleasure8&page=RSS%3A%20%E5%9C%A8Windows%E4%B8%8B%E9%9D%A2%E7%94%A8Mongrel%E4%BD%9C%E4%B8%BARails%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%B9%B3%E5%8F%B0&referrer=)![](http://c.live.com/c.gif?NC=31263&amp%3BNA=1149&amp%3BPI=88469&amp%3BRF=&amp%3BDI=3919&amp%3BPS=85545&amp%3BTP=pleasure8.spaces.live.com&amp%3BGT1=pleasure8)