Skip to content

Instantly share code, notes, and snippets.

@dolzenko
Created November 12, 2010 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolzenko/674125 to your computer and use it in GitHub Desktop.
Save dolzenko/674125 to your computer and use it in GitHub Desktop.
script/rails_with_ssl
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
# Augmented version which starts server in SSL mode. Creating certificates: http://www.zunisoft.com/?p=740
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
opts = super.merge({
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
# Use this to let WEBrick generate certificates (may cause issues with Firefox)
# :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
# :SSLCertName => [ [ "CN", WEBrick::Utils::getservername ] ]
# Use below for stored static certificate
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
File.open(File.expand_path("../../config/certs/server.key", __FILE__)).read),
:SSLCertificate => OpenSSL::X509::Certificate.new(
File.open(File.expand_path("../../config/certs/server.crt", __FILE__)).read),
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
})
opts
end
end
end
require 'rails/commands'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment