Since the original tech preview release of FastCGI last year, we've been seeing a lot of requests for getting Ruby on Rails running with our FastCGI.  Theoretically, since the FastCGI component uses a standard protocol to support FastCGI-enabled applications, this shouldnt be an issue - but, in practice, this is very far from reality.  After factoring in setup problems, configuration, and variations in runtime behavior / protocol deviations, every single FastCGI application we've looked at has required quite some effort to support properly.

So, for FastCGI Tech Preview 2, I spent some time researching what it would take to enable Ruby on Rails, resulting in "experimental" RoR support in the TP2 release.  It is "experimental" because we did only limited testing, and given our lack of experience with Ruby its very hard to tell whether a real Ruby application will work as expected at this point.

I am confident that the experience can be improved significantly with community testing, and any necessary fixes to both the FastCGI component and Ruby.  I am looking forward to any feedback/bug reports that can help us get there - please feel free to leave comments on the blog, or post to IIS FastCGI forums.

Without further ado, these are the 10 steps get RoR working with FastCGI TP2:

Read this first - platform limitations

The steps below can be used to install Ruby on Rails on a Windows Server 2003 operating system, and configure it to work with the Microsoft IIS FastCGI technical preview 2 release.  Unfortunately Windows XP does not support the required configuration necessary for the FastCGI TP2 component to run RoR, and Windows Vista's version of FastCGI TP2 uses a different mechanism to run RoR (post on how to get that working in the near future).  The initial steps to install Ruby on Rails described here are similar for Windows XP, Windows Server 2003, and Windows Vista.

FastCGI TP2 Installation

1) Download and install FastCGI Technical Preview 2

Download the appropriate TP2 package for your OS, which in this case means either the IIS6 32bit FastCGI or IIS6 64bit FastCGI.  You can read more about this on my previous blog post.  Here is the synopsis of the install steps:

This will install FastCGI on your machine, and enable us to configure it manually later.  We will not be using the automatic configuration support in the installer because we will need some customizations specific for RoR later.

Ruby Installation

2) Download and install Ruby(latest tested version was 1.8.5-22 Final)

3) Install Rails Open a new command line window, and run the gem installer:

> gem install rails --include-dependencies

4) Download and install RoR IIS extensions

The RubyForIIS.exe package contains the FastCGI client library on which RoR is dependent in order to use its dispatch.fcgi script.  During the installation, the installer will ask for the location of the Ruby directory - be sure to point the installer to the directory where you installed Ruby, for example, f:Ruby.

During the installation, you may get an error "Unable to write to file ...msvcp7.dll"  - press ignore to continue.  If you want to double-check that everything went well, open a command prompt, and type in: > irb <enter> > require 'fcgi' <enter> If you see "true", then its installed correctly.  If not, re-install and give the right path this time.

5) Fix the Ruby CGI script

This is a workaround for an IIS-specific behavior in Ruby that actually does not work with IIS.  Feel the irony.  Quick background - NPH, or No Parsed Headers, is a CGI mode of operation in which the CGI program produces a complete response including the http headers, instead of supplying the headers to the web server and letting the webserver manage them.  Most of today's webservers, including IIS, manage response headers on their own - for example, IIS enables a number of web server features that modify response headers in order to enable functionality like caching, compression, etc.  Ruby's CGI script assumes that IIS always requires NPH, and this of course completely breaks the FastCGI component because it does not even support NPH   The funnier thing is that even IIS CGI does not require NPH, and doesnt use it by default.  This is one of the things that totally makes sense to be fixed in a future Rails release to provide a more cohesive experience on IIS.

Open <f:Ruby>libruby1.8cgi.rb, and edit line 559 of the script to remove:                                        "OR /IIS/n.match(env_table([‘SERVER_SOFTWARE’])".

You can also download the already fixed script  if you dont want to do surgery yourself.

Creating a sample Ruby application

At this point, if you followed the instructions above, you should have Ruby on Rails installed and ready to go on your Windows machine.  Now, we will create a sample RoR application to use with the FastCGI component:

6) Create a sample Ruby app

Open a command line window, change to a base directory where you want to create your app, and type:

> rails myapp > cd myapp > ruby scriptgenerate controller test

This creates the myapp RoR application, and then generates a sample "test" RoR controller.  Edit this controller to display some useful stuff by opening appcontrollertest_controller.rb, and pasting the following into it:

class TestController < ApplicationController   def index     render :text=>"The index action"   end   def about     render :text=>"Testing app v1.0"   end end

Configure the RoR application with IIS and FastCGI

We are almost there, so don't panic.  I promise to not exceed 10 steps

7) Create a website for your RoR app

Create a new website on port 81 pointing to the public directory of your rails app, which for me was f:rubymyapppublic:

8) Create the RoR FastCGI handler mapping

Because RoR uses SEF (search engine friendly) urls, it needs to use a wildcard mapping to forward all requests to FastCGI / RoR mapping - unlike PHP, which requires .PHP files to be mapped to the PHP / FastCGI mapping.  Because of reliance on wildcard mapping, FastCGI can only be used to run RoR on Windows Server 2003 (since Windows XP's version of IIS doesnt support wildcard mappings).  This is the sole reason why this walkthrough is limited to W2k3.

To create the mapping, click the "Configuration" button on the website, and "Insert" the handler mapping to "fcgiext.dll" FastCGI ISAPI handler (which you installed in step 1):

Be sure to clear the "Verify that file exists" checkbox.

9) Create the FastCGI application pool for your website

If you remember in step 1, when we installed the FastCGI TP2 package, we didnt use the installer's support for registering a FastCGI program.  This is because RoR requires some custom settings in the FastCGI config file that the installer doesnt surface.

Because of this, we will manually create this configuration by editing the %windir%system32inetsrvfcgiext.ini configuration file (NOTE that for 64bit installations, you will also need to make the same edits to %windir%syswow64inetsrvfcgiext.ini):

[Types] *:85358523=Ruby

[Ruby] ExePath=F:Rubybinruby.exe Arguments=F:Rubymyapppublicdispatch.fcgi IgnoreDirectories=0 IgnoreExistingFiles=1 QueueLength=1000 MaxInstances=4 InstanceTimeout=30 InstanceMaxRequests=200

- Replace the ExePath with the path to your ruby.exe. - Replace the Arguments with the path the dispatch.fcgi script inside your application. - Replace the "85358523" number above with your site id.  You could omit this if you are not planning to run multiple Ruby applications on your machine. You can get it from the logging properties of your website:

This configuration shows the several new configuration / behavior features we needed to add to TP2 in order to get Ruby working.  This includes support for specifying arguments to the FastCGI executable (per pool), the ability to scope FastCGI extension mappings to a particular site id (so that you can map the same extension to different pools for different sites), and the ability to execute as a wildcard mapping that only processes files that do not exist on disk.  More information on all of these later.

10) You are done!

At this point, you should be up and running.  Hit up http://localhost:81/test/about, and you should get the RoR response from our test controller.

Please try this out with your real RoR apps, and let me know how it went / what issues you hit.  Your feedback will be instrumental in getting to a production quality FastCGI support for RoR in a future release.  Feel free to leave comments on this blog, or hit us up at the FastCGI forums on www.iis.net.

Finally, I want to thank Brian Hogan, without whose invaluable help in explaining the workings of Ruby On Rails and how to get it installed on Windows, I wouldn't have been able to get even this far.  He has a book on Ruby on Rails coming out soon, and I hope that we can get IIS FastCGI and RoR to play well enough together to be mentioned in it

10 steps to get Ruby on Rails running on Windows with IIS FastCGI- 摘自网络的更多相关文章

  1. Running a Remote Desktop on a Windows Azure Linux VM (远程桌面到Windows Azure Linux )-摘自网络(试了,没成功 - -!)

                              A complete click-by-click, step-by-step video of this article is available ...

  2. ruby on rails在fedora18上install

    ruby on rails 在fedora18下的安装 天朝的网络原因,安装不是很顺畅,所以把过程记录下备用 前面下载rubygem什么的都比较快,新建一个project的时候会出问题 gem new ...

  3. Fedora 16下安装ruby on rails

    Fedora 16下安装ruby on rails 最近在windows下写了些rails小程序,问题一个接一个,到最后终于坚信了那句话“windows不适合用于ruby on rails开发”.于是 ...

  4. 10个基于 Ruby on Rails 构建的顶级站点

    本文系国内 ITOM 行业领军企业 OneAPM 工程师翻译整理自 Raviraj Hegde 的文章 Top Sites Built with Ruby on Rails. 就其本身而言,Ruby ...

  5. How To Use PostgreSQL with Your Ruby on Rails Application on Ubuntu 14.04

    How To Use PostgreSQL with Your Ruby on Rails Application on Ubuntu 14.04 链接来自于:https://www.digitalo ...

  6. ruby on rails on windows

    这次想系统学会rails,最终目标是将redmine改造成顺手的工具,主要的手段就是开发redmine插件.虽然网上都推荐使用类Unix系统,可手头只有win7系统,就安装了. 难免会遇到这样那样的问 ...

  7. 通过Ruby On Rails 框架来更好的理解MVC框架

    通过Ruby On Rails 框架来更好的理解MVC框架   1.背景    因为我在学习软件工程课程的时候,对于 MVC 框架理解不太深入,只是在理论层面上掌握,但是不知道如何在开发中使用 MVC ...

  8. Ruby on Rails框架开发学习

    学习地址:http://www.ixueyun.com/lessons/detail-lessonId-685.html 一.课程概述 软件开发在经历了面向过程编程的阶段,现在正大行其道的是敏捷开发, ...

  9. [ruby on rails] 跟我学之(3)基于rails console的查增删改操作

    本章节展开对model的介绍:包括查增删改操作.紧接着上面一节<[ruby on rails] 跟我学之HelloWorld> 创建模型 使用命令创建模型 创建表post,默认自带两栏位 ...

随机推荐

  1. <span> <div> 局部 keydown ,keyup事件。页面部分div $(document) 无效,可能焦点,添加焦点。

    前天改一个bug, js 实现的一个 面板拖拉,左右各两个列表,中间面板画线连接,页面左侧列表选中后,key 事件无效.右侧选中确有效,很奇怪,查看源码,左侧选中后,$(document).on(&q ...

  2. 如何助力企业 APP 在竞争中占据先机?

    做好产品的六字真言:刚需.痛点.高频 --周鸿祎 好的产品是需要不断打磨的.在开发任何产品之前,都需要进行严格的假设和调研,找到刚需,找到痛点.然后就是不断的验证自己的假设,不断地在适当的试错过程中成 ...

  3. HDU1412

    大水题.. 求集合的并 /* */ #include<algorithm> #include<iostream> #include<string.h> #inclu ...

  4. 李洪强iOS开发之XMPP

      XMPP历史 这个xmpp框架在2008年开始,不过是一个简单地RFC实现.提供一个最小的代理去接受三种xmpp的基本类型presence.message.iq.因为framwork只提供了最小的 ...

  5. 【转】VMware设置共享文件夹之后Ubuntu中看不到怎么办?

    一.共享文件夹设置好了,但是在虚拟机中的Ubuntu系统下却看不到,怎么办? 一种可能的原因是系统没有自动挂载,解决办法: 1.安装:               sudo apt-get insta ...

  6. altium designer 13 学习之添加汉字

    在altium desginer中如果你是想添加英文还是比较方便的,基本直接就可以输入了,但是添加中文就不是那么简单了,下面不介绍下如何在altium designer中快速的添加自己想要的中文 工具 ...

  7. update多表陷阱

    今天同学发了个sql题目 A1表 B1表 id num id snum 1 10 1 90 2 2000 3 4000 3 30 B表的数据插入A表当中 最后的结果 A表 1 90 2 2000 3 ...

  8. js监听输入框值的即时变化onpropertychange、oninput

    js监听输入框值的即时变化onpropertychange.oninput 很多情况下我们都会即时监听输入框值的变化,以便作出即时动作去引导浏览者增强网站的用户体验感. // //   要达到的效果 ...

  9. Django用户认证系统(二)Web请求中的认证

    在每个Web请求中都提供一个 request.user 属性来表示当前用户.如果当前用户未登录,则该属性为AnonymousUser的一个实例,反之,则是一个User实例. 你可以通过is_authe ...

  10. UVA 10041 Vito's Family (中位数)

      Problem C: Vito's family  Background The world-known gangster Vito Deadstone is moving to New York ...