Rails, Windows, IIS and HTTPS

Image for post
Image for post

Once upon a time there was somebody how wants to create a ruby on rails application running on Windows …

Normaly a bad decision, because Windows is not a good development and runtime environment regarding ruby on rails etc.

But the customer only wants windows and what else counts ;-)

So I implemented the application and everything works fine for some time.

Until we got the idea to scan articles using an android phone. Nowadays HTML and JavaScript in modern browsers supports camera access and the like, so what should be the problem. At first there was no problem at all, everything goes it’s way, and we could scan.

But then, one day the chrome browser went secure, also on mobiles …

That sounds not to be a problem, but due to the camera api it means chrome does not further accept access from scripts got from an insecure server, means not using https.

So what is the solution. Go HTTPS.

On windows this is a challenge, or simply was a challenge to me and others on the web.

But finally I got it running and here is how.

First you have to install the IIS from windows through the Microsoft Web Platform Installer.

Image for post
Image for post

And you also need the HttpPlatformHandler, also hidden here ;-)

Image for post
Image for post

You also should have done an installation of ruby and ruby on rails, maybe simply by using the RailsInstaller.

Be sure that your applications works as expected by running it in a normal rails console.

Then the next step is to start the Manager for the IIS using the control panel and administration. You should see something like this in the language of your environment.

Image for post
Image for post

Here we will add our new website. Select the Sites folder and create a new website with a right click of the mouse.

This should lead you to the next dialog. Fill in the selected fields and end with OK. You can use any sitename you like. The path should be the root path to your ruby on rails application. Do not forget to select https, if you want a secure connection and also select a certificate — in my case a development certificate.

Image for post
Image for post

You also need a configuration file in your application path, so that IIS knows how to start and serve your website. So create a new web.config in your application directory and add the following:

<?xml version=”1.0" encoding=”UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name=”httpplatformhandler” path=”*” verb=”*” modules=”httpPlatformHandler” resourceType=”Unspecified” requireAccess=”Script” />
</handlers>
<httpPlatform stdoutLogEnabled=”true” stdoutLogFile=”rails.log” startupTimeLimit=”20"
processPath=”c:\RailsInstaller\Ruby2.1.0\bin\ruby.exe”
arguments=”&quot;C:\RailsInstaller\Ruby2.1.0\bin\rails&quot; server -p %HTTP_PLATFORM_PORT% -b 127.0.0.1">
<environmentVariables>
<environmentVariable name=”RAILS_ENV” value=”production”/>
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>

Check your paths to ruby and rails ;-)

Also check that you already started an application pool, otherwise it does not work. Use the following dialog to start it.

Image for post
Image for post

In the end configure ssl for you application, if you need to …

Image for post
Image for post

… and restart it.

After this you should get a running rails application right beyond your secure ip and the default port.

In the end I missed also to open the firewall for the used port. But after that everything works as expected.

Hope this helps someone.

Missing something? Comments and suggestions are welcome.

Developer since the 80'th, working at Forschungszentrum Jülich (http://www.fz-juelich.de) …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store