Mighty Interactive Homepage

Rails on Windows

Deploying to IIS with lighttpd and Mongrel

by Joseph Jaramillo

Section 2 - Configuration

Now that your environment has been properly configured to run Rails applications, we must configure Windows to automatically launch the required processes. We will configure Mongrel to launch and run individual instances of the Rails application, and lighttpd to proxy requests from IIS to the Mongrel processes.

Step 1 - Configuring Mongrel as a Windows Service

Mongrel is an application server. Each Mongrel process will run one instance of the Rails application. For demonstration purposes we will set up two Mongrel processes.

  1. Open a Command Prompt.
  2. Navigate to the Rails application directory created in Section 1 - Step 11 (c:\test\testapp) in the console.
  3. Type each of the following lines and press ENTER after each:

    mongrel_rails service::install -N rails_app_4001 -p 4001
    mongrel_rails service::install -N rails_app_4002 -p 4002

    This creates two Windows Services, "rails_app_4001" and "rails_app_4002".

  4. Type each of the following lines and press ENTER after each:

    net start rails_app_4001
    net start rails_app_4002

    This starts each of the Windows Services we just created.

  5. Open a browser window and navigate to each of the following URLs.

    • → http://localhost:4001
    • → http://localhost:4002

    You should see the same "Welcome aboard" message as in Section 1 - Step 11.

  6. Open "Services" from the "Administrative Tools" menu on the Start Menu.

  7. Locate the "rails_app_4001" and "rails_app_4002" services. For each of these, do the following:

    1. Double-click the Service.
    2. Change "Startup type:" to "Automatic"
    3. Click "Apply"
    4. Click "OK"
  8. Close the Services window, Command Prompt, and any web browser windows previously opened.

Mongrel configuration as a Windows Service is complete.

Step 2 - Configuring lighttpd

lighttpd is very fast web server with proxy capabilities. We will use it to distribute requests to our Mongrel processes.

  1. Download the lighttpd configuration file.
  2. Copy the file into the config/ directory under your Rails app directory (c:\test\testapp\config). This file has been pre-configured to support this setup (2 Mongrel processes at ports 4001 and 4002 respectively, Rails app at c:\test\testapp). After copying the file should be located at c:\test\testapp\config\lighttpd.conf

Step 3 - Configuring lighttpd as a Windows Service

  1. Open a Command Prompt.
  2. Type the following and press ENTER:

    instsrv lighttpd "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"
  3. Open the "Run" command from the Start Menu. Type the following and press ENTER:

    regedit
  4. Locate the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lighttpd

  5. Right-click the key (appearing as a folder named "lighttpd"), and click "New," and "Key." Name the key "Parameters" and press ENTER.
  6. Right-click the key "Parameters", and click "New," and "String Value." Name the String Value "Application" and press ENTER.
  7. Double-click the String Value "Application" and enter the following for "Value data:"

    "C:\Program Files\LightTPD\LightTPD.exe"

    Click "OK."

  8. Right-click the key "Parameters" (appearing as a subfolder of "lighttpd" named "Parameters"), and click "New," and "String Value." Name the String Value "AppParameters" and press ENTER.

  9. Double-click the String Value "AppParameters" and enter the following for "Value data:"

    Note: The following lines should be entered as one line with a single space in between. This line has been broken into two for publishing purposes.

    -f "C:\test\testapp\config\lighttpd.conf"
    -m "C:\Program Files\LightTPD\lib" -D

    Click "OK" and then close the Registry Editor.

  10. Open "Services" from the "Administrative Tools" menu on the Start Menu.

  11. Scroll down to "lighttpd." If its "Status" is listed as "Started," right-click it and click "Stop."
  12. Double-click "lighttpd" to edit it. Ensure "Startup type" is set to "Automatic" and click the "Log On" tab.
  13. Click the "This account:" radio button, and click the "Browse" button. Type "network" in the "Enter the object name to select (examples):" box, and then click the "Check Names" button. This will fill in the box to read "NETWORK SERVICE." Click "OK."
  14. Enter the appropriate password into the "Password:" and "Confirm password:" fields.
  15. Click "Apply." Click "OK."
  16. Right-click "lighttpd" and click "Start."
  17. Open a web browser and go to the following URL: http://localhost:8001
  18. Verify that you see the Rails "Welcome aboard" page.
  19. Close the Services window, Command Prompt, and any web browser windows previously opened.

lighttpd configuration as a Windows Service is complete. lighttpd will by default launch and proxy requests to the two Mongrel processes. It will listen on port 8001 on localhost only.

Step 4 - Configuring IIS to proxy to lighttpd

  1. Select "Manage Your Server" from the Start Menu.
  2. Select "Manage this application server" for the Application Server.
  3. Click the + next to "Internet Information Services (IIS) Manager" and continue to drill down to "Default Web Site." If you are asked, please click "Unblock" for the Microsoft Management Console. NOTE: You can choose to set up another web site if you wish, but for testing purposes the assumption is that this machine will serve the Rails application by default.
  4. Right-click "Default Web Site" and click "Properties."
  5. Click the "ISAPI_Rewrite" tab and click the "Edit" button.
  6. Type the following into the editor:

    RewriteProxy (.*) http://localhost:8001/$1
  7. Click "Apply." The Helicon Config Editor will close.

  8. Click "Apply." Click "OK."
  9. Open a web browser and point it to the following URL: http://localhost
  10. Click the "About your application’s environment" link to verify the application is functioning.
  11. Close the Application Server window, Manage Your Server window, and any web browser windows previously opened.

IIS configuration is complete.

This concludes the Ruby on Rails setup for Windows. Your server will now proxy all requests to the lighttpd service, which in turn distributes requests to each of the Mongrel services configured.

When configuring additional applications in the future there will generally be no new installations necessary. You will simply configure new Mongrel and lighttpd Windows Services.

Previous Page | 1 | 2 | 3

E-mail Newsletter

Sign up to receive the bi-weekly New York Minute marketing newsletter. You will also receive periodic agency announcements and invitations. View latest issue.


Ruby on Rails – A Mighty Tool

Check out our new section on Ruby on Rails, the Web development platform everyone's talking about. Developers – download our plugins.


You Make Money, We Make Money

Ask us about our results-based pricing model, where we're true business partners with our clients. View a case study about how this approach increased ROI 500% in one year for Esscentual Brands.


Getting results

  • Next Student

    NextStudent, one of the nation's premier education funding companies, had significant traditional and direct mail programs in place when they came to Mighty Interactive.

    View this case study »


PPC Calculator

Options

change to dark background change to light background