Skip to content

Instantly share code, notes, and snippets.

@mindscratch
Created February 25, 2013 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mindscratch/5028880 to your computer and use it in GitHub Desktop.
Save mindscratch/5028880 to your computer and use it in GitHub Desktop.
Start WEBrick with SSL enabled. ## Usage bundle exec ruby script/secure_rails s -e <environment> -p <port>
#!/usr/bin/env jruby
%W{rails/command/server rack webrick webrick/https}.each { |lib| require lib }
ENV['HTTPS'] = 'on'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
:environment => (ENV['RAILS_ENV'] || 'development').dup,
:daemonize => false,
:pid => File.expand_path(File.join('tmp', 'pids', 'server.pid')),
:config => File.expand_path('config.ru'),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_PEER,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read('/path/to/id_rsa'), 'password'),
:SSLCertificate => OpenSSL:X509::Certificate.new(File.read('/path/to/id_rsa.pub')),
:SSLCACertificateFile => '/path/to/ca.crt',
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
})
end
end
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment