eng рус  
small_logo

Ruby on Rails™ application development team


Rails and SSL

Sometimes it’s necessary to encrypt traffic from some parts of site. Thereto you had to use HTTPS protocol. HTTPS is widely used all over the WEB world in applications demanding safe connecting, for example, in payment systems.

Rails developers confront by some problem: Mongrel and Webrick are not support SSL encription.

A quotation from Mongrel FAQ:

Does Mongrel support SSL? No, it isn’t efficiently to make SSL encription support in Ruby web-server because you can use any of popular web-servers, if would work faster.

Web-server setup

Apache

<VirtualHost *:80>
   ServerName localhost
   ServerAlias 127.0.0.1

   ProxyPass / http://localhost:3000/
   ProxyPassReverse / http://localhost:3000
   ProxyPreserveHost on
</VirtualHost>

<VirtualHost *:443>
    SSLEngine On
    ServerName localhost
    ServerAlias 127.0.0.1

    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000
    ProxyPreserveHost on

    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile "/etc/httpd/ssl/mysite.crt"
    SSLCertificateKeyFile "/etc/httpd/ssl/mysite.key"

    # Установите X-FORWARDED_PROTO для работы с ssl_requirement плагином
    RequestHeader set X_FORWARDED_PROTO 'https'
</VirtualHost>

Our advice: Use Apache 2.x.x and higher to avoid great number of problems.

nginx

server {
  listen 443;
  ssl on;

  # ssl сертификат
  ssl_certificate /etc/nginx/certs/server.crt; 
  # ssl ключ
  ssl_certificate_key /etc/nginx/certs/server.key; 

  location / {
     # Установите X-FORWARDED_PROTO для работы с ssl_requirement плагином
     proxy_set_header X-FORWARDED_PROTO https;
  }
}

Plugin

Use plugin SSL Requirement for comfortable work with HTTPS connection.

>
class ApplicationController < ActiveRecord::Base
    include SslRequirement
end
class AccountController < ApplicationController
    ssl_required :signup, :payment
    ssl_allowed :index

    def signup
      # Non-SSL access will be redirected to SSL
    end

    def payment
      # Non-SSL access will be redirected to SSL
    end

    def index
      # This action will work either with or without SSL
    end

    def other
      # SSL access will be redirected to non-SSL
    end
  end

Have a nice work!

61 comments к “Rails and SSL”

Leave your comments here

not for public

About Us Projects Blog Contacts
© 2008, hashtrain.com team

hashtrain.com.sharedcopy.com