Friday, March 02, 2007

FTGU - Rails on Windows - Mongrel Proxied by IIS with Oracle Backend

The name of the example app throughout this tutorial is "myapp", and there are several assumptions I make. You already have your project in svn somewhere and are deploying it to production. In my case, I deployed an intranet site, and that's why we have integrated Windows domain Single Sign On (for more on SSO see my next post). I also assume you already have your tsnames.ora file which you can copy from somewhere and are deploying with an Oracle database that is already configured.
Versions I Used

Windows Server 2003
IIS 6.0
Rails 1.2.2
Ruby 1.8.5
Mongrel 1.0.1
Mongrel Service 0.3.1
SVN 1.4.2
Reverse Proxy Fix 1.0.2
Ruby OCI8 0.1.16 (mswin32)
Oracle Client 10.2.0.1.0 (Administrator Install)

ISAPI_Rewrite

I use the full version in my setup. The cost was $99 (and definitely worth it).
Install

Install: Windows Server 2003
Go to Control Panel -> install additional components. Choose Network Services (includes IIS) (this requires W2K3 Server install disc)
Install: Windows Updates.
Go to Control Panel -> administrative tools. Turn on IIS.

Quad Click Installs***NotesHome
isapi_rwf_x86_0066.exe(or latest version)Home
ruby185-21.exeHome
svn-1.4.2-setup.exeYou may want to get a version that is the same as your repository. Be careful! Newer versions will auto-upgrade any repository they touch to the newer format.Home
TortoiseSVN-1.4.1Make sure that TortoiseSVN is linked to the same version of svn that you are using. The svn version number is in the name ('TortoiseSVN-1.4.1.7992 -win32-svn-1.4.2.msi') of the file ('...svn-1.4.2...')Home
jdk-6-windows-i586.exeInstallation Help?Home
eclipse-SDK-3.2.1-win32.zip
extracted to C:\Programs Files
Home
Oracle Client 10.2.0.1.0Administrator InstallHome

***Really it's more than a double click install, you click the link to download, then you click to save the file, then you double click the file to install.
Copy your tnsnames.ora file to => C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN
Download: ruby-oci8 from http://rubyforge.org/projects/ruby-oci8/

CLI Installs

ruby ruby-oci8-0.1.16-mswin32.rb
gem update
gem update --system
gem install rails -y
gem install mongrel --include-dependencies
gem install mongrel_service --include-dependencies
gem install mechanize --include-dependencies
gem install daemons --include-dependencies
gem install fastercsv --include-dependencies
gem install fastthread --include-dependencies

Eclipse

Open Eclipse. Change workspace directory to C:\rails, and set as default (don't ask again). Help > Software Updates > Find and Install > Search for updates to Eclipse and install them. Eclipse will likely need to restart. Go here in a new tab of your browser.
Back in Eclipse go back to Help > Software Updates > Find and Install > Enter the Eclipse Update Sites, RDT, RadRails, and Subclispe as "New Remote Sites" under 'Find and install new software'.
Check out the project from the subversion repository.

Bark at the Dog!

Open Command Prompt
cd \rails\myapp

start mongrel server:
mongrel_rails start -p 4001 -e production -c "C:\rails\myapp" -r "C:\rails\myapp" -t 0 -n 1024 -a "127.0.0.1"

Make sure Mongrel is serving myapp correctly by going to http://localhost:4001 in a browser.

Reverse Proxy Fix

Install the reverse proxy fix so that Mongrel can find the files that IIS will be asking for:
ruby script/plugin install http://svn.napcsweb.com/public/reverse_proxy_fix

and the install script will ask you for the base URL! If you're not sure, you can change it later by going here:
myapp/vendor/plugins/reverse_proxy_fix/lib/config.rb
BASE_URL="http://127.0.0.1/myapp"

There was a bug in the version of reverse_proxy_fix which I used. I fixed it by doing the following:
Modify line 21 of myapp/vendor/plugins/reverse_proxy_fix/lib/reverse_proxy_fix.rb
ActionController::Base.asset_host = BASE_URL + '/public'

Setup Proxy for Authentication

Setup the authentication for IIS passed through to mongrel (that's what the ,A,D does on the end of the rewrite line.
First make the file writeable (will be read-only by default).
Add to the bottom of C:\Program Files\Helicon\ISAPI_Rewrite\httpd

# FOR MYAPP APPLICATION
RewriteProxy /myapp(.*) http\://localhost:4001$1 [I,U,A,D]

If you don't already have SOS (Single Sign On) authentication set up in your app and you want it then make your way to my next post... :) On the other hand if you are not using IIS for Windows Domain authentication you won't need the ",A,D" at the end of the RewriteProxy /myapp(.*) line above.

Automate Everything!

Then install the mongrel service:
mongrel_rails service::install -N myapp -p 4001 -e production -c "C:\rails\myapp" -r "C:\rails\myapp" -t 0 -n 1024 -a "127.0.0.1" -l "log/mongrel.log" -P "log/mongrel.pid"

Start the service (You can also use the services control panel!):
net start myapp

The myapp web application should now be available at http://127.0.0.1/myapp

1 hashings:

Brian Hogan said...

A lot of this is already covered in articles on my site at http://www.napcs.com/, the home of the reverse_proxy_fix plugin.

I'm interested to know why you needed to add /public/ to the asset_base_host in the plugin. That's never been necessary for any of my users. I just checked out the plugin to a fresh app and had no problems getting it to work without that, so I am not sure thet the plugin has a "bug". Please get back to me ASAP - bphogan at gmail dot com

This blog began on Monday, September 27, 2004.
Hits since 2/20/2007:
free hit counters
free hit counters